errors with Elif expected indented block
我试图为我的应用程序创建一个菜单,菜单有4个选项,当用户输入所选值时,每个选项都应该返回正确的信息。我不断地发现elif语句有错误。我是个新手,所以请你理解我来自哪里。非常感谢。
当我缩进while-ans:i时,在缩进elif ans==2之后,会收到一个错误:说无效语法。
elif ans==2<---这个错误在我缩进时总是说缩进块错误或syntex无效。
def打印菜单(self,car):打印("1.按板号搜索")打印("2.按价格搜索")打印("3.删除3")打印("4.exit 4")
循环=真循环时:PrimtTyMeNuu()ans==输入("请从列表中选择")。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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") |
你有一个没有主体的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | loop=True while loop: print_menu() ans = int(input("Please choose from the list")) if ans==1: print("These are the cars within this platenumber") # return some valid information about plate numbers elif ans==2: print("These are the prices of the cars") # return some valid information about pricing elif ans==3: print("Delete the cars") # Perform car deletion action and return elif ans==4: # I am assuming this is the exit option? in which case # return without doing anything else: # In this case they have not chosen a valid option. Send # A message to the user, and do nothing. The while loop will run again. print("please choose a correct option") |
而且,您的代码对我来说有点混乱。看起来你要去EDOCX1[1]不管怎样,这意味着你的循环只执行一次。另外,