我正在试图制作一个与用户一起播放“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:哎呦。谢谢。 –
非常感谢!如果有领带,你能帮助关于重新启动功能的部分吗? –