【发布时间】:2019-04-03 13:29:48
【问题描述】:
所以我有一些代码,像这样:
while loopCode == 1:
userCommand = raw_input('Type a command (type \'help\' for syntax): ')
if userCommand == help:
print 'flight: this command will be used to list a flight'
print 'restaurant: you will be prompted to type the name of the restaurant, and how much you will spend there'
如您所见,while 循环内有一个if 条件。但是当我被提示输入文本时,我应该输入“帮助”来激活条件。但是当我这样做时,while 循环会忽略条件。这是为什么呢?
【问题讨论】:
-
确保您问题中的代码与您机器上的代码完全相同(包括缩进等)
-
您的代码引用了一个名为
help的变量,您尚未在代码中定义该变量。 -
没有办法退出那个循环...
-
谢谢@khelwood,我必须确保我声明它是一个字符串。
标签: python if-statement while-loop raw-input