我想爲我的應用程序創建一個菜單,菜單有4個選項,並且這些選項中的每一個都應該在用戶輸入所選值時返回正確的信息。我不斷收到Elif報表的錯誤。 我是一個新手,所以請理解從哪裏來。 非常讚賞。錯誤與Elif預期的縮進塊
當我縮進while回答:我會收到一個錯誤說,無效的語法縮進elif ans == 2後。
elif ans == 2 < ---當我縮進時,此錯誤一直說indention塊錯誤或syntex無效。
DEF print_menu(個體,汽車):
打印( 「1.Search由platenumber」) 打印( 「2.Search由價格 」) 打印(「 3.刪除3」) 打印(「4 .Exit 4 「)
循環=真
while循環: print_menu() ANS ==輸入(」 請從列表中選擇「)
if ans==1:
print("These are the cars within this platenumber")
return platenumber_
while ans:
if ans==2:
elif ans==2:
print("These are the prices of the cars")
return price_
elif ans==3:
print("Delete the cars ")
return delete_
elif ans==4:
return Exit_
loop=False
else:
raw_input("please choose a correct option")
你有'while ans:',之後沒有縮進。如果你用':'結束了一行,那麼當我縮進之後,我應該有一個縮進 – Craicerjack
我收到一個錯誤,說無效的語法 – Sam
從你的問題開始,儘管它很難理解工作中的邏輯,你的'return'語句很奇怪縮進,並且你的'if'語句中間有'while'語句。你爲什麼首先在「while」循環中? – Craicerjack