【发布时间】:2022-01-06 13:23:45
【问题描述】:
def menu():
print("1. Create new User")
print("2. View User")
print("3. Update User")
print("4. Quit ")
menu()
selection=input("Select a menu- Input a number:")
if not selection.isdigit():
print("You have input a non digit value. Select again:")
selection=input("Select a menu- Input a number:")
else:
selection = int(selection)
if selection==1:
print("::menu 1::")
newName = input("Input first name : ")
newSurname = input("Input last name : ")
elif selection==2:
print("::menu 2::")
elif selection==3:
print("::menu 3::")
elif selection==4:
print("you have logged out")
else:
print("There is no menu",end=" ")
print(selection)
print()
menu()
selection=input("Select a menu- Input a number:")
所以当我运行代码并首先输入错误值(非整数)然后输入一个不在菜单中的数字时,我希望它能够让我输入另一个数字,例如正确的数字,例如 1 但它似乎在那之后它没有做任何事情,我不知道如何解决它可以有人帮忙。它只在我第一次做时才承认 1-4,但在任何错误值之后才承认。
【问题讨论】:
标签: python if-statement input while-loop menu