【发布时间】:2014-02-03 05:08:36
【问题描述】:
我正在尝试在 Python 中创建一个小程序,它从列表中选择一个随机字符串并打印该字符串。但通常程序会两次选择相同的字符串。
有没有办法确保每个字符串只输出一次?
到目前为止我的代码:
from random import choice
food = ['apple', 'banana', 'strawberry', 'blueberry', 'orange']
print 'You should eat today :' + choice(food)
print 'You should eat tomorrow :' + choice(food)
【问题讨论】:
-
尝试类似 - for foodItem in food: print foodItem