While循环python故障



我最近在高中上了一门游戏开发课,我们一直在用Mac的终端运行python代码来制作一个基于文本的游戏。我认为这是python 2.7的一个版本,我遇到了一个错误

while Menuselect != "play":
    MenuSelect = raw_input("Type 'quit' to exit - 'credits' for credits - Type 'play' to startn")
    MenuSelect = MenuSelect.lower()
    if MenuSelect == "quit":
        SystemExit(0)
    elif MenuSelect == "credits":
        print("Lmao, only Matt made this")
    else:
        print("You mistyped. 10/10")
print(": You wake up in a dark room, you don't know where you are or how you got here :")

当我尝试运行它并输入'play'来停止循环时,它只是再次继续循环。有什么问题吗?

您正在检查变量名称"Menuselect"与小写"s",但分配raw_input到一个名为"Menuselect"大写"s"的变量。将'while'语句改为

while MenuSelect != "play":

最新更新