I am trying to implement a try exception in Python which when inputting a char/string instead of an int, catches the exception.
However, when inputting the letter 'a' the program crashes, returning the following error:
num = input('Enter integer number: ') File "<string>", line 1, in
<module> NameError: name 'a' is not defined
This is my code:
if __name__ == '__main__': #main function
num = input('Enter integer number: ')
try:
num = int(num)
except ValueError:
print "Invalid input."