【发布时间】:2021-08-17 08:07:49
【问题描述】:
所以我正在尝试自己做一个猜谜游戏,当游戏结束时,我希望它会提示玩家是否想再次玩,这样输入是或否:
Guess a number between 1 to 10: 7
YOU WON!!!!
Do you want to continue playing? (y/n) y
Guess a number between 1 to 10: 7
YOU WON!!!!
Do you want to continue playing? (y/n) n
Thank you for playing!
我设法让游戏正常运行,但我无法再次玩游戏。我被困在这里:
guess = int(input("Guess a number between 1 and 10: "))
while True:
if guess > num:
print("Too high, try again!")
guess = int(input("Guess a number between 1 and 10: "))
elif guess < num:
print("Too low, try again!")
guess = int(input("Guess a number between 1 and 10: "))
else:
print("You guessed it! You won!")
replay = input("Do you want to continue playing? (y/n) ")
if replay == "y":
**what to insert here???**
else:
break
我不知道在 if 语句中输入什么内容,如果用户按“y”并允许我重新开始游戏,我的代码将返回到循环顶部。
任何帮助将不胜感激!请不要给我整个解决方案,而是尝试给我提示,以便我自己解决这个问题!谢谢!
【问题讨论】:
标签: python-3.x if-statement while-loop conditional-statements