I’m learning how to use python right now. I found a problem while learning about definitions that I don’t understand. I give a simple menu with choice 0-4. If the user chooses above 4, there supposed to receive a message that says “This is not a valid choice…”
However, if you input a value greater than or equal to 10, it doesn’t return anything but the menu…no message.
Thanks in Advance for Any Thoughts.
Here is My Code:
# Multitasker
# Allows User to Pick an Item that is Defined.
def exit():
print("See You Later!")
def task1():
print("This is Task 1!")
def task2():
print("This is Task 2!")
def task3():
print("This is Task 3!")
def task4():
print("This is Task 4!")
choice = None
while choice != "0":
print(
"""
Multitask Selector
0 - Quit
1 - Task 1
2 - Task 2
3 - Task 3
4 - Task 4
"""
)
choice = input("Pick a Task Between 1-4:\t#")
print()
# Exit
if choice == "0":
exit()
# Task 1
elif choice == "1":
task1()
# Task 2
elif choice == "2":
task2()
# Task 3
elif choice == "3":
task3()
# Task 4
elif choice == "4":
task4()
# Not a Correct Selection
elif choice > "4":
print("That is not a valid choice. Please Select a Task Between 1-4.")
You’re comparing choice, which is a string (I’m assuming Python 3 from your print functions), with “4”, also a string.
This works lexicographically:
If you want numerical comparisons, you have to turn choice into a number, e.g.