【发布时间】:2017-06-15 21:28:46
【问题描述】:
我有这个问题;我分步骤总结一下
- 让程序通过输入将 7 只动物添加到列表中 (DONE)
- 让程序从该列表中随机选择 3 只动物(完成)
- 如果选择的动物都相同,打印“Bingo!” ;如果没有,则循环输入,直到用户按下“X”或获得“Bingo!”。
我在最后一步遇到问题,我尝试到处搜索并尝试了许多方法,但代码没有做正确的事情。代码如下:
import random
bingoList=[]
generatedList=[]
def generateCards():
for i in range(0,3):
print(random.choice(bingoList))
generatedList.append(a)
for i in range(0,7):
a=input("Enter an animal: ")
if (a.isdigit()==False):
bingoList.append(a)
else:
printprint("You are not allowed to input numbers; program stopping...")
exit()
print("All the animals have been stored, let's start the game..")
generateCards()
【问题讨论】:
-
“我试过到处搜索并尝试了很多方法,但代码没有做正确的事情。” 您的代码似乎没有尝试任何方法全部。请与我们分享您尝试的最后一件事。
-
@Kevin if (generatedList==a,a,a): print("Bingo")