I am trying to make a loop which keeps giving an error message until the right number (0-4) is entered. But the current else statement is not working; Nothing happens when any other text (or no data) is entered. I am a newbie.
def my_function():
def menu():
"""
Display the menu
"""
print("0) Go back to main menu")
print("1) some texts")
print("2) some texts")
print("3) some texts")
print("4) some texts")
def my_main():
while True:
menu()
choice = input("--> ")
if choice == "0":
return
elif choice == "1":
print("1")
return
elif choice == "2":
print("2")
return
elif choice == "3":
print("3")
return
elif choice == "4":
print("4")
return
else:
print("You can only choose from the menu.")
my_main()
Aucun commentaire:
Enregistrer un commentaire