-1
你好,我有這樣的代碼Python的if語句不正確服用輸入
print('Please enter each category you would like (type ex to exit)')
x = True
while x == True:
category = input('Next:')
if str(category).lower != 'ex':
categories.append(category)
print ('Here are your current categories' + str(categories))
else:
x = False
break
,如果我輸入「EX」不破環,我想不通爲什麼它不工作
你實際上不調用'.lower()'函數。改用'str(category).lower()'。 – Delgan
ahhhhhh非常感謝你 – skalerz
另外,由於'x = False',你的'break'語句是多餘的,因爲無論如何你都要走出循環。 Python中的一個常見做法是「while True:... break」,它簡化了一些事情,因爲你不再需要'x'變量。 – Delgan