python输出不重复的单词_【Python 练习】随机显示不重复的单词

By D01phin ,BJ,20150818

【题目:】创建能以随机顺序显示一组单词的程序。要求该程序能打印出所有单词,但不能重复!# coding=utf-8

# random show word                           #

# By D01phin,BJ,20150818                     #

# function: 1、random show words             #

#           2、show all words and no repeat  #

#--------------------------------------------#

import random

word  = ["Dolphin","Angel","computer","hacker","information","program"]

same = word

for i in range(0,6):

show = random.choice(same)

print(show)

same.remove(show)

input("\nHey,man! You got it !")

此程序的缺陷是:循环中的次数,要根据你在word中输入单词的个数去修改,原来是写了个可以动态修改循环次数的,但是调试中总有问题,总是执行了三次(执行次数:单词个数 / 2),便不再执行,希望大神能出来解答一下,下面我将贴出源码。# coding=utf-8

#--------------------------------------------#

# random show word                           #

# By D01phin,BJ,20150818                     #

# function: 1、random show words             #

#           2、show all words and no repeat  #

#--------------------------------------------#

import random

word  = ["Dolphin","Angel","computer","hacker","information","program","hello","iphone"]

same = word

for i in word:

show = random.choice(same)

print(show)

same.remove(show)

input("\nHey,man! You got it !")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值