Skip to main content
 首页 » 编程设计

python之while循环python故障

2025年05月04日14del

我最近在高中学习游戏开发类(class),我们一直在使用 Mac 的终端运行 python 编码来制作基于文本的游戏。以为是python 2.7的版本,遇到错误

while Menuselect != "play": 
    MenuSelect = raw_input("Type 'quit' to exit - 'credits' for credits - Type 'play' to start\n") 
    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 :") 

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

请您参考如下方法:

您正在检查变量名“Menuselect”的小写“s”,但将 raw_input 分配给一个名为“MenuSelect”的变量,其名称为大写的“S”。将“while”语句更改为

while MenuSelect != "play": 

它应该可以工作。