我正在尝试创建一个简单的 Rock, Paper, Scissors 游戏,但我总是收到标题中指定的错误。这是代码。大约在第 21 行弹出错误。我是初学者,所以请保持相对简单。
import random
def displayIntro():
print('Hello! This a game of Rock, Paper, Scissors, against the computer.')
print()
def humanChoice():
playerChoice = ''
while playerChoice != 'Rock' and playerChoice != 'Paper' and playerChoice != 'Scissors':
print('Please choose: Rock, Paper or Scissors. BTW: Please type your choice with the first letter as a capital.')
playerChoice = input()
return playerChoice
a = ["Rock", "Paper", "Scissors"]
def computerChoice():
compChoice = random.choice(a)
def winner():
if playerChoice == compChoice:
print('You tied! The computer also chose ' + playerChoice)
elif playerChoice == Rock and compChoice == Scissors:
print('You won! You chose ' + playerChoice + ' and the computer chose ' +compChoice)
elif playerChoice == Paper and compChoice == Rock:
print('You won! You chose ' + playerChoice + ' and the computer chose ' +compChoice)
elif playerChoice == Scissors and compChoice == Paper:
print('You won! You chose ' + playerChoice + ' and the computer chose ' +compChoice)
else:
print('You lost! You chose ' + playerChoice + ' and the computer chose ' +compChoice)
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'Yes':
displayIntro()
humanChoice()
computerChoice()
winner()
print('Do you want to play again? (yes or no)')
playAgain = input()