How to validate user input properly?

I prefer making a function to get input from the user and then just calling that function. Something like:


def get_input(prompt, options):
	while True:
		for option in options:
			print(f"{options.index(option)} {option}")

		user_input = input("=> ")

		try:
			user_input = int(user_input)

			if options[user_input]:
				return user_input
		except:
			pass

		print("Invalid Input")





i = get_input("Are You a: ", ["Lion", "Tiger", "Wolf", "Platypus"])


if i == 3:
	print("You are a cool person")

else:
	print("You are a 'meh' person")
1 Like