嗨,我正在做剪刀石頭布的遊戲,我做了下面的腳本至今:,石頭,剪刀(蟒蛇3.3)
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()
但是當我運行它,我得到我所做的錯誤「錯誤:結果未執行」有人可以告訴我爲什麼這是?謝謝。
'UserChoice'和'CpuChoice'設置爲整數,然後將它們與字符串進行比較。 –
在其他地方,做一個打印的值,你會爲什麼 –
不相關的問題,但我建議你映射ramdom數字字符串,而不是其他方式。 –