我想为我的应用程序创建一个菜单,菜单有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