python⽯头剪⼦布while循环_在⽯头、布、剪⼑类游戏中使⽤
while循环。(Pyt。。。
我尝试使⽤while循环,这样这个游戏就可以继续玩了,除⾮⽤户输⼊的字符串不是myList中的选项之⼀。我该把这个while循环放在哪⾥?(抱歉,我对编码⽐较陌⽣)。import random
def AceDiamondSpade():
#Set up a list which contains Ace, Diamond and Spade so that the computer can randomly choose one of them.
myList = ["Ace", "Diamond", "Spade"]
#
choice = input("Ace, Diamond, or Spade? ")
computerChoice = random.choice(myList)
playAgain = True
if str(choice) != str(myList[0]) and str(choice) != str(myList[1]) and str(choice) != str(myList[2]):
playAgain = False
print ("invalid! Please enter again or make sure that you have capitalized the first letter of your answer!")
if str(choice) == str(computerChoice):
print ("You and the computer selected the same thing, you tie!")
if str(choice) == "Ace" and str(computerChoice) == "Diamond":
print ("You selected Ace, and the comptuer selected Diamond, you win!")
if str(choice) == "Diamond" and str(computerChoice) == "Spade":
print ("You selected Diamond, and the Computer selected Spade, you win!")
if str(choice) == "Spade" and str(computerChoice) == "Ace":
random在python中的意思print ("You selected Spade, and the comptuer selected Ace, you win!")
if str(choice) == "Ace" and str(computerChoice) == "Spade":
print ("You selected Ace, and the computer selected Spade, you lose!")
if str(choice) == "Spade" and str(computerChoice) == "Diamond":
print ("You selected Spade, and the computer selected Diamond, you lose!")
if str(choice) == "Diamond" and str(computerChoice) == "Ace":
print ("You selected Diamond, and the computer selected Ace, you lose!")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。