所以我有一些代碼,像這樣: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'如您所見,循環(huán)中有一個if條件while。但是當我被提示輸入文本時,我應該輸入“幫助”以激活條件。但是當我這樣做時,while循環(huán)會忽略條件。這是為什么?
1 回答

呼啦一陣風
TA貢獻1802條經(jīng)驗 獲得超6個贊
這是因為 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
添加回答
舉報
0/150
提交
取消