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
186,966 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 Ovesen
Adam Ovesen
1,609 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...