The following function takes an input prompt argument. It requires the user give an input of either 1 or 2, and prints "Invalid Input" if anything else is given as an input. The function then again asks for the user's input. I would like to know if there is a cleaner solution that does not involve the try/except statement or recursion.
def input_params(prompt):
while True:
try:
user_input = int(input(prompt))
if user_input == 1 or user_input == 2:
return user_input
else:
print("Invalid Input")
input_params(prompt)
except ValueError:
pass