I have this python code that prints a menu to the user and returns his choice:
def menu():
choice = input("Enter your choice ->")
while choice not in OPTIONS:
choice = input("Try again, Enter your choice ->")
return choice
I was wondering what is the most pythonic way to check the input of the user, I thought maybe to implement as follows:
def menu():
choice = int(input("Enter your choice ->"))
while not (MIN_OPTION <= choice <= MAX_OPTION):
choice = int(input("Try again, Enter your choice ->"))
return choice
But I found this option less readable (I can’t know all the options, only the first and the last).
I’d be happy to know what is the most pythonic and readable way to do this task.
Thanks