我很好奇为什么这个程序没有循环。该程序将运行一次,但当另一个游戏是玩它不记录赢家和退出
任何帮助都将不胜感激
下面是Python程序:
import random
random.seed()
print ("For each round please select from the following warriors: ")
print ("'C' or 'c' for Cowboy")
print ("'N' or 'n' for Ninja")
print ("'B' or 'b' for Bear")
print ("'Q' or 'q' for quit")
print()
gamesPlayed = 0
print ("Round", gamesPlayed +1, ":")
warriorStr = input("Please choose a warrior: ")
warriorStr = warriorStr.lower()
while not warriorStr.isalpha():
print()
print ("That's not a valid choice!")
warriorStr = input("Please enter a weapon: ")
computer = random.choice("cnb")
count = 0
winCount = 0
lossCount = 0
tieCount = 0
if warriorStr == "n" or "N" and computer == "c" or "C":
winCount = winCount + 1
print ("You win")
elif warriorStr == "c" or "C" and computer == "b" or "B":
winCount = winCount + 1
print ("You win")
elif warriorStr == "b" or "B" and computer == "n" or "N":
winCount = winCount + 1
print ("You win")
elif warriorStr == "c" and computer == "n":
lossCount = lossCount + 1
print ("Computer wins")
elif warriorStr == "b" and computer == "c":
lossCount = lossCount + 1
print ("Computer wins")
elif warriorStr == "n" and computer == "b":
lossCount = lossCount + 1
print ("Computer wins")
elif warriorStr == "c" and computer == "c":
tieCount = tieCount + 1
print ("You tied")
elif warriorStr == "n" and computer == "n":
tieCount = tieCount + 1
print ("You tied")
elif warriorStr == "b" and computer == "b":
tieCount = tieCount + 1
print ("You tied")
gamesPlayed = gamesPlayed + 1
print()
print ("Round", gamesPlayed +1, ":")
warriorStr = input("Choose a warrior: ")
if warriorStr == "q" and "Q":
print("Game Over!")
print ("You have played a total of", gamesPlayed, "games.")
print ("You won", winCount, "times")
print ("The computer won", lossCount, "times")
print ("You tied", tieCount, "times")
把整件事绕一圈。 试试这个:
相关问题 更多 >
编程相关推荐