2016-11-18 33 views
0

上午在學校的項目中,我試圖使用一段時間True循環,以便從輸入中獲得特定答案。我嘗試了以下內容,並將IDLE標籤作爲語法錯誤分解。while循環不接受break函數,歸類爲語法錯誤?

while True: 
    RequestTea = input("What tea would you like? English Breakfast, Green Tea or Earl Grey? ").lower() 
if RequestTea.lower() not in ('earl grey','english breakfast','green tea'): 
    print("Not an appropriate choice.") 
else: 
    break 

任何人都可以請幫忙嗎?我不明白爲什麼它不接受循環功能。

非常感謝!

+2

因爲你'if'語句不是你的循環的一部分。 –

+2

可能是一個縮進問題。把這樣的變量名稱大寫也不是一個好主意;爲類名保留該表格。 –

+0

感謝您的提示。將嘗試從現在開始使用小寫變量名稱。 @JimStewart –

回答

0
while True: 
    RequestTea = input("What tea would you like? English Breakfast, Green Tea or Earl Grey? ").lower() 
    if RequestTea.lower() not in ('earl grey','english breakfast','green tea'): 
     print("Not an appropriate choice.") 
    else: 
     break 

縮進塊

+0

非常感謝。我的錯誤。@ blue-monday –

+1

Typo問題應該關閉,而不是回答。 –

+0

我明白這個問題 - 將來會更加密切。 –