【问题标题】:While loop python glitchwhile循环python故障
【发布时间】:2015-10-19 23:50:28
【问题描述】:

我最近在高中上过一个游戏开发课程,我们一直在使用 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 与 MenuSelect 不同

标签: python python-2.7 terminal


【解决方案1】:

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

while MenuSelect != "play":

它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2017-11-03
    相关资源
    最近更新 更多