【发布时间】:2019-08-24 12:14:48
【问题描述】:
我正在制作这款石头、纸、剪刀游戏,而且我已经完成了很多工作。但是,我无法正确打印最终分数。无论情况如何,我的总回合数、总胜场数和平局数总是为 0。
我一直试图在循环中添加这些变量,但是,我似乎无法弄清楚这一点。
import random
# a rock, paper, scissors game
loop = True
while loop is True:
win = 0
tie = 0
lose = 0
rounds = 0
usrchoice = input("Rock, Paper or Scissors? (Quit ends): ") # user makes a choice
if usrchoice.title() == "Rock":
pass
...
if computer_choice == "Scissors":
print("You WIN!")
win = win + 1
rounds = rounds + 1
elif computer_choice == "Rock":
print("It's a tie!")
tie = tie + 1
rounds = rounds + 1
else:
print("You LOSE!")
lose = lose + 1
rounds = rounds + 1
我希望输出是任何东西,当然取决于用户,而不仅仅是 0。像这样:
>>> You played 0, and won 0 rounds, playing tie in 0 rounds.
【问题讨论】:
-
rounds = 0, wins = 0 and ties = 0,你在 while 循环中设置 0,所以无论你添加什么,它都设置为 0,从 while 循环中删除这些行并放在循环之前
标签: python python-3.x