嗨,我正在做一个石头剪子游戏,到目前为止我已经做了以下脚本:
def main():
from random import randint
UserChoices = input("'rock', 'paper' or 'scissors'? \n Input: ")
if UserChoices == "rock":
UserChoice = 1
elif UserChoices == "paper":
UserChoice = 2
elif UserChoices == "scissors":
UserChoice = 3
CpuChoice = randint(1,3)
if UserChoice == CpuChoice:
print("DRAW!")
elif UserChoice == "1" and CpuChoice== "3":
print("Rock beats scissors PLAYER WINS!")
main()
elif UserChoice == "3" and CpuChoice== "1":
print("Rock beats scissors CPU WINS")
main()
elif UserChoice == "1" and CpuChoice== "2":
print("Paper beats rock CPU WINS!")
main()
elif UserChoice == "2" and CpuChoice== "1":
print("paper beats rock PLAYER WINS!")
main()
elif UserChoice == "2" and CpuChoice== "3":
print("Scissors beats paper CPU WINS!")
main()
elif UserChoice == "3" and CpuChoice== "2":
print("Scissors beats paper PLAYER WINS!")
main()
elif UserChoice == "1" and CpuChoice== "2":
print("cpu wins")
main()
else:
print("Error: outcome not implemented")
main()
但是当我运行它时,我得到了我犯下的错误“错误:结果没有实现”有人能告诉我为什么吗?谢谢您。
最佳答案
这和所有其他类似的比较:
elif UserChoice == "1" and CpuChoice == "3":
... 应该是:
elif UserChoice == 1 and CpuChoice == 3:
换句话说,您应该将
int
s与int
s进行比较,而不是像现在这样将int
s与字符串进行比较。关于python - 石头,纸,剪刀(python 3.3),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21732790/