我正在用Python编写石头,剪刀,剪刀的游戏。游戏将继续循环播放,直到玩家选择退出为止。当玩家决定最终退出时,我想让程序打印玩家和计算机分数。我有以下代码,但是我写的分数计数器似乎不起作用。它仅显示1,其他两个为0。有人可以解释为什么会发生这种情况以及如何解决吗?
ValidPlays = ['r','p','s','q']
while PlayerChoice.lower() not in ValidPlays:
print(PlayerChoice,'is not a valid play. Please enter a valid choice.')
PlayerChoice = input('Your move: ')
while PlayerChoice != 'q':
from random import randint
ComputerChoice = randint(1,3)
CompMove = ''
if ComputerChoice == 1:
CompMove = 'r'
elif ComputerChoice ==2:
CompMove = 'p'
else:
CompMove = 's'
print("Computer's move:",CompMove)
RockWinMsg = 'Rock smashes Scissors!'
PaperWinMsg = 'Paper covers Rock!'
ScissorsWinMsg = 'Scissors cut Paper!'
PlayerScore = 0
CompScore = 0
TieScore = 0
if PlayerChoice.lower() == 'r' and CompMove == 'r':
print('Tie!')
TieScore = TieScore +1
elif PlayerChoice.lower() == 'r' and CompMove == 'p':
print(PaperWinMsg)
print('Computer wins!')
CompScore = CompScore +1
elif PlayerChoice.lower() == 'r' and CompMove == 's':
print(RockWinMsg)
print(PlayerName,'wins!')
PlayerScore = PlayerScore +1
PlayerScore = PlayerScore +1
if PlayerChoice.lower() == 'p' and CompMove == 'r':
print(PaperWinMsg)
print(PlayerName,'wins!')
elif PlayerChoice.lower() == 'p' and CompMove == 'p':
print('Tie!')
TieScore = TieScore +1
elif PlayerChoice.lower() == 'p' and CompMove == 's':
print(ScissorsWinMsg)
print('Computer wins!')
CompScore = CompScore +1
if PlayerChoice.lower() == 's' and CompMove == 'r':
print(RockWinMsg)
print('Computer wins!')
CompScore = CompScore +1
elif PlayerChoice.lower() == 's' and CompMove == 'p':
print(ScissorsWinMsg)
print(PlayerName,'wins!')
PlayerScore = PlayerScore +1
elif PlayerChoice.lower() == 's' and CompMove == 's':
print('Tie!')
TieScore = TieScore +1
PlayerChoice = input('If you would like to play again, enter your move, otherwise enter q quit: ')
print('Player Score:',PlayerScore)
print('Computer Score:',CompScore)
print('Ties:',TieScore)