I want to prompt the user with a separate exception error if they have entered a float over any other invalid string. Currently I get the same error if a string like "hello" is entered or a float like 2.5. Which exception should I be using just to filter float values? Thanks
print('Enter 1 for option 1')
print('Enter 2 for option 2')
print('Enter 3 for option 3')
print('Enter 4 to quit')
flag = True
x = -1
while(flag):
try:
x = (int(input('Enter your choice: ')))
if((x >= 1) and (x <= 4)):
flag = False
x = x
else:
print('The number should be between 1 and 4')
except TypeError:
print('Choice should be an integer not a float')
except ValueError:
print('Choice should be a number')
except NameError:
print('Choice should be a number')