如何在 'why' 循环中添加 'if' 命令
How do I add 'if' commands inside a 'why' loop
所以我有一些代码,像这样:
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
条件语句。但是当我被提示输入文本时,我应该输入 'help' 来激活条件。但是当我这样做时,while
循环会忽略条件。这是为什么?
因为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
所以我有一些代码,像这样:
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
条件语句。但是当我被提示输入文本时,我应该输入 'help' 来激活条件。但是当我这样做时,while
循环会忽略条件。这是为什么?
因为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