这是我的代码:
def main():
mycolours = ['R', 'G', 'B', 'Y', 'P', 'O']
myguess = 'RGBY'
total_guess = 5
x = random.shuffle(mycolours[:4])
for i in range(total_guess):
if myguess == x:
print('CORRECT')
else:
print('TRY AGAIN')
main()x不是从列表中返回4个随机字符串,而是返回值none。
发布于 2015-11-07 12:05:27
您可以通过随机导入来混洗元素,所以让
import random
a = [1,2,3,4,5]然后你可以说
print random.sample(a,2)它将打印出来
[4,2]如果你想要很多随机的数字集合,那么
z=[]
for i in range(3):
z.append(random.sample(a,2))现在z将如下所示
[[3, 4], [1, 3], [7, 6]]希望这能有所帮助!
https://stackoverflow.com/questions/33578749
复制相似问题