我正在試圖製作一個與用戶一起播放「Rock Paper Scissors Lizard Spock」的程序。我已經完成了大部分工作,但我遇到的一個問題是,如果遊戲達到平局,我希望忽略這一結果,並重復循環。另一種說法是,我希望有三項輸贏結果。另外,爲了完全解決我剛纔所說的問題,如果用戶在連續兩次獲勝或者連續兩次獲得勝利,它會完全退出循環。python循環再次如果某些值?
對於第一個問題,我嘗試使用繼續,但這根本不起作用。我在這個網站上經歷了幾個搖滾紙剪刀的問題,但是我沒有看到任何適用於此的答案。第一個問題是重中之重;第二隻是頂級的櫻桃。
這裏是我的代碼(這是一個有點長,我很抱歉):
import random
Rock = "Rock"
Paper = "Paper"
Scissors = "Scissors"
Lizard = "Lizard"
Spock = "Spock"
Words = (Rock, Paper, Scissors, Lizard, Spock)
def The_Game (x):
for i in range(3):
y = random.choice(Words)
x = input("Choose your weapon! Rock, paper, scissors, lizard, or spock?")
if x == y:
print(y)
print("Tie. Try again!")
else:
if x == Rock:
if y == Paper:
print(y)
print("Paper covers Rock. You lost this round!")
elif (y == Spock):
print(y)
print("Spock vaporizes Rock. You lost this round!")
elif (y == Lizard):
print(y)
print("Rock crushes Lizard. You won this round!")
else:
print(y)
print("As always, Rock crushes Scissors. You won this round!")
elif (x == Paper):
if y == Scissors:
print(y)
print("Scissors cut Paper. You lost this round!")
elif (y == Lizard):
print(y)
print("Lizard eats paper. You lost this round!")
elif (y == Rock):
print(y)
print("Paper covers Rock. You won this round!")
else:
print(y)
print("Paper disproves Spock. You won this round!")
elif (x == Scissors):
if y == Rock:
print(y)
print("As always, Rock crushes Scissors. You lost this round!")
elif (y == Spock):
print(y)
print("Spock melts scissors. You lost this round!")
elif (y == Paper):
print(y)
print("Scissors cut Paper. You won this round!")
else:
print(y)
print("Scissors decapitate Lizard. You won this round!")
elif (x == Lizard):
if y == Rock:
print(y)
print("Rock crushes Lizard. You lost this round!")
elif (y == Scissors):
print(y)
print("Scissors decapitate Lizard. You lost this round!")
elif (y == Paper):
print(y)
print("Lizard eats Paper. You won this round!")
elif (y == Spock):
print(y)
print("Lizard poisons Spock. You won this round!")
else:
if y == Paper:
print(y)
print("Paper disproves Spock. You lost this round!")
elif (y == Lizard):
print(y)
print("Lizard poisons Spock. You lost this round!")
elif (y == Scissors):
print(y)
print("Spock melts scissors. You won this round!")
else:
print(y)
print("Spock vaporizes Rock. You won this round!")
x = ("Let's play Rock Paper Scissors Lizard Spock! Best 2 of three!")
print(x)
The_Game(x)
Yes = "Yes"
No = "No"
p = input("Play again? (Yes or No) ")
if p == Yes:
The_Game(x)
else:
print("Thanks for playing!")
如果有人可以幫助,那將是美好的!我只是一個Python初學者。
他在「if x == y:」塊中包含了兩個選擇相同的情況。 – senshin
@senshin:哎呦。謝謝。 –
非常感謝!如果有領帶,你能幫助關於重新啓動功能的部分嗎? –