In the code below I am trying to catch an error thrown if i enter any other value than an integer. (I used the string 'six' and the float '1.5')
The error thrown in the command window by the code is:
Traceback (most recent call last):
File "C:\Documents and Settings\Smythville\My Documents\Python\Stuff\Ch4\ex1-6.py", line 59, in <module>
a = int(raw_input("\nTry a number!"))
ValueError: invalid literal for int() with base 10: 'six'
Expand|Select|Wrap|Line Numbers
- a = int(raw_input("\nTry a number!"))
- try:
- if a >= 0 and a <= 9:
- print "\nYour number is between or equal to 0 and 9."
- else:
- print "\nYour number is not between or equal to 0 and 9."
- except ValueError:
- print "Could not convert data to an integer."
Any Ideas?
Thanks
Eclipse