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 trialNoam Pfeifel
895 Pointswhen im trying to write the last part at this video the program give me the error "invalid literal for int with base 10"
I wanted to know how can fix that? thank you
3 Answers
Alissa Kuzina
5,835 PointsHey! I had tne same issue so I started to google it and try to change my code. The thing I realised that an error occures when we want a charcter to be an integer. But it's not true and we have no ecxeption for it (I dont't know why as it's ValueError).
And after a long time i found the solution:
try:
number_tickets = int(number_tickets)
if number_tickets > tickets_remaining:
raise ValueError
except ValueError as err:
print("Try again. We have only {} tickets.".format(tickets_remaining))
As you can see I have no .format(err) . I think there's a problem with it. Btw if you have an error in different place yu can copy your code so we can see what's wrong.
Youssef Moustahib
7,779 PointsI am getting the same issue:
try:
howmuch = int(howmuch)
if howmuch > tickets_remaining:
raise ValueError("Sorry, the maximum amount you can have is {}".format(tickets_remaining))
except ValueError as err:
print("Sory we have ran into an error, {}, please try again".format(err))
Youssef Moustahib
7,779 PointsThe problem is when it tries to convert it into an int. Before we added the "raise" and it was just "except ValueError" it would have caught it and produced your warning. e.g
try:
number_tickets = int(number_tickets)
except ValueError:
print("hey thats not a number")
That would work