Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSeth Estevis
441 PointsInvalid Syntax for an Exception, Please Help
I am getting a SyntaxError for line two where I am trying to create an exception. I want to create this exception because a user might enter "two" instead of "2" which breaks my program. Please advise on why I am getting this error. Thank you!
number=int(input("Please pick a number. "))
except ValueError:
print("Please pick an integer.")
if number < 100:
print("{} is less than 100!".format(number))
if number > 100:
print("{} is greater than 100!".format(number))
if number == 100:
print("{} equals 100!".format(number))
elif number == 200:
print("{} is the magic number!".format(number))
1 Answer
Steven Parker
231,264 PointsIf you want to catch errors, you need a "try" block before your "except". Take a look at the examples on the documentation pages that cover handling exceptions.
Seth Estevis
441 PointsSeth Estevis
441 PointsThank you for your advise! I found it very helpful reading the documents.