所以我有一些代码,像这样:
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'
如您所见,在if
循环中有一个while
条件。但是,当系统提示我输入文本时,应该键入“ help”以激活条件。但是,当我这样做时,while
循环将忽略条件。为什么会这样?
答案 0 :(得分:0)
这是因为if语句未正确缩进,并且其条件未指定为字符串'help':
while 1:
userCommand = input('Type a command (type \'help\' for syntax): ')
if userCommand == 'help':
print ('flight: this command will be used to list a flight')
break