Python 官方文档:入门教程 => 点击学习
By D01phin ,BJ,20150818【题目:】创建能以随机顺序显示一组单词的程序。要求该程序能打印出所有单词,但不能重复!# coding=utf-8 # random show Word
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 !")
--结束END--
本文标题: 【Python 练习】随机显示不重复的单
本文链接: https://lsjlt.com/news/186325.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0