繁体   English   中英

为什么我的Python 3代码无法正常工作?

[英]Why isn't my Python 3 code working?

我必须为我的汇总项目准备一个文本编辑器(从Adventures into Zork中剥离)游戏。

这是我对第一个区域的决定。

second = True
while second:
    firstLog = input(">")

这是我遇到问题的地方,因为当我输入“ Inside”或“ In”时,脚本将终止。

if firstLog = "Inside" or "In" or "Space Ship":
    print("There is a small " color.Bold + "console " + color.End + "in front of you.")
    print("You can " + color.Bold + "input " + color.End + "or" + color.Bold + "Exit" + color.End)
    second = False

另外,如果我输入其他任何内容,它也会终止,而不是打印此内容并重新启动循环。

else:
    "Not valid."
    second = True

一些事情。 最后,您缺少打印语句。

else:
    print("Not valid.")

if firstLog应该再次声明变量比较。

if firstLog == "Inside" or firstLog == "In" or firstLog == "Space Ship":

更好的是,您可以执行以下操作:

if firstLog.lower() in ["inside", "in", "space ship"]:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM