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 trial
Christopher Cunnyngham
748 PointsIssue with error exceptions: Project 1
I'm having a problem with the integer type ValueError in Project 1. I was successful in dealing with the first condition: tickets ordered > tickets available. Then followed with:
except ValueError as err:
print("Sorry we ran into an issue! {}".format(err))
But what returns is:
"Sorry we ran into an issue! invalid literal for int() with base 10: 'ten' "
Any pointers? Thanks in advance.
1 Answer
Chris Freeman
Treehouse Moderator 68,468 PointsThis error can happen when passing a string containing a floating point value to int(). From the Stack Overflow post:
>>> str(5/2)
‘2.5’
>>> int(‘2.5’)
File “<stdin>”, line 1
int(‘2.5’)
^
SyntaxError: invalid character in identifier
>>> int(str(5/2))
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ValueError: invalid literal for int() with base 10: ‘2.5’
>>> int(float(str(5/2)))
2