I'm new in programming and I have an issue when doing the input validation.
My program requires to input number from 1 to 10 or the letter y
but it seems that I cannot do an error handler for this.
def checkingInput():
while True:
try:
a = input()
if 10 >= a >= 1 or a == 'y':
return value
else:
print('Invalid input!')
except NameError:
print('Name error!Please try again!')
except SyntaxError:
print('Syntax Error!Please try again!')
print()
but could you please confirm that? – jamylak May 10 '12 at 5:19SyntaxError
is not an exception that normally happens at runtime. – Ignacio Vazquez-Abrams May 10 '12 at 5:31ValueError
instead ofSyntaxError
. Also you can't compareints
withstrings
so you should change your line toif a == 'y' or 1 <= int(a) <= 10
– jamylak May 10 '12 at 5:32