Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Handle Exceptions

Where i .format(err) i just get "invalid literal for int() with base 10: 'blue' instead of how many tickets are left

I've rewatch the video a few times, and i just can't quite get what I'm doing wrong. here is the code: try: num_tickets = int(num_tickets) if num_tickets > tickets_remaining: raise ValueError("There are only {} tickets remaining".format(tickets_remaining)) except ValueError as err: print("Oh no, something seems to not be right. {}. Please try again".format(err)) else:

1 Answer

Steven Parker
Steven Parker
212,260 Points

There's nothing wrong, the code is doing exactly as should be expected.

The message showing the number of tickets left is only issued when the number requested exceeds the number available.

But if you enter a word instead of a number, the system generates an error when the "int" function is called (before that test is reached), and the message you are seeing is the appropriate system message for that situation.

Adam Raboch
Adam Raboch
7,193 Points

Cassidy, you are right. This error also occurred in the previous lesson where we learned to handle errors. I find it confusing that we are combining error messages in the code, but the output is less than satisfactory...