Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';我的Python 3代码不能工作吗?_Python_Python 3.x - Fatal编程技术网

为什么不是';我的Python 3代码不能工作吗?

为什么不是';我的Python 3代码不能工作吗?,python,python-3.x,Python,Python 3.x,我必须为我的总结性项目准备一个文本编辑器(冒险到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 " +

我必须为我的总结性项目准备一个文本编辑器(冒险到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"]:
没什么。 最后一个问题是您缺少打印语句

else:
    print("Not valid.")
if firstLog应该再次声明变量比较

if firstLog == "Inside" or firstLog == "In" or firstLog == "Space Ship":
更好的是,你可以这样做:

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

展示你的问题,明白了@carcigenicate你的意思是说如果firstLog==“In”或firstLog==“In”或firstLog==“Space Ship”:?另外,你的
if
条件与你认为的不一样。您可以将对象与
=
、而不是
=
链接多个布尔表达式进行比较。表达式
“Inside”
是真实的,因为它是非空的string@Tobias这是对的
如果firstLog==“Inside”或“In”
将始终是
True
,但无论如何,您使用的是赋值运算符。显示一个可以说明您的问题的表达式。明白了!@carcigenicate您的意思是
如果firstLog==“Inside”或firstLog==“In”或firstLog==“太空船“:
?此外,如果您的
条件与您认为的条件不符,您的
条件也会与您认为的条件不符。您可以将对象与
=
、而不是
=
链接多个布尔表达式进行比较。表达式
“Inside”
是真实的,因为它是非空的string@Tobias这是对的
如果firstLog==“Inside”或“In”
将始终为
True
,但无论如何,您使用的是赋值运算符。多么尴尬!感谢您的帮助,效果非常好!多么尴尬!感谢您的帮助,效果非常好!