嘿,我寫了下面的代碼,一切似乎工作正常,除非它應該是一個平局我不斷得到「name2勝」以及何時答案應該是無效的。我不知道什麼是錯的,因爲我的邏輯看起來是正確的。我的「搖滾,紙,剪刀」代碼有問題
print("Welcome to Rock, Paper, Scissors!")
print("Let's Begin ...")
name1 = input("Player 1: What's your name?")
name2 = input("Player 2: What's your name?")
print("Hello " + name1 + " and " + name2)
print(name2 + ": Close your eyes!")
choice1 = input(name1 + ": enter 'r' for rock, 'p' for paper, and 's' for Scissors: ")
print("Great choice! Now - cover your answer and ask " + name2 + " to choose. \n\n\n")
choice2 = input(name2 + ": enter 'r' for rock, 'p' for paper, and 's' for scissors: ")
if(choice1 == "r" , choice2 == "p"):
print(name2 + " wins!")
elif(choice1 == "r" , choice2 == "s"):
print(name1 + " wins!")
elif(choice1 == "r" , choice2 == "r"):
print("It is a draw")
elif(choice2 == "r" , choice1 == "p"):
print(name1 + " wins!")
elif(choice2 == "r" , choice1 == "s"):
print(name2 + " wins!")
elif(choice1 == "p" , choice2 == "s"):
print(name2 + " wins!")
elif(choice1 == "p" , choice2 == "p"):
print("It is a draw!")
elif(choice2 == "p" , choice1 == "s"):
print(name1 + " wins!")
elif(choice1 == "s" , choice2 == "s"):
print("It is a draw!")
else:
print("Invalid asnwer")
print("Thanks for playing Rock, Paper, scissors")
哪裏你的想法到把一個逗號你的if語句從何而來? – Soviut
邏輯是正確的,語法也是如此......至少正確的修改不會導致解釋器發生錯誤。您可能想要在if語句中重新查看逗號,這些逗號會導致編譯錯誤。 –