如何在python中为主谋游戏菜单解决这个无限循环


ans = True
while ans:
print("What would you like to do?")
print("""
r register a new user
s show the score board
p play  a game
q quit
""")
ans = input("What would you like to do?")
if ans=="r":
"""
If user 1 chooses option 'r'
"""
player_1 = input("What is the name of the new user?")
print("Welcome", player_1, "!")

嗨,我正在用python编写MasterMind游戏,在编写游戏菜单时遇到了一个无限循环。我是python的新手,所以我可能对这些概念没有最好的理解。

再添加一个退出条件。您需要将代码中的ans更新为False才能退出循环。

elif ans == "q":
ans = False

最新更新