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

Python Python Basics All Together Now Handle Exceptions

ErrorValue

Hi,

I am having trouble understanding what is happening. The first ValueError I inputted was to help when the user inputted a string instead of an integer. That worked fine. I then inputted a second ValueError in order to handle when the user inputted more tickets than remaining. That works well! The problem however is when I go back to try to break the code with a string again, the error comes out weird this time.

```TICKET_PRICE = 10

tickets_remaining = 100

while tickets_remaining >=1: print('There are {} ticket remaining!'.format(tickets_remaining)) user_name = input('What is your name? ') tickets_wanted = input('Hi {}, how many tickets would you like to purchase? '.format(user_name)) #Expect a ValueError to happen and handle it appropriately... remember to test it out! try: tickets_wanted = int(tickets_wanted) if tickets_wanted > tickets_remaining: raise ValueError('There are only {} tickets remaining'.format(tickets_remaining)) #raise a ValueError if the request is for more tickets than are available except ValueError as err: #Include the error text in the output. print('Oh no, we ran into an issue. {}. Please try again'.format(err)) else: tickets_cost = tickets_wanted * TICKET_PRICE print('Great {}! Your total will be ${}'.format(user_name,tickets_cost)) choice = input('Would you like to proceed with your purchase {}?(Y/N) '.format(user_name))

  if choice.lower() == 'y':
  #Gather credit card information and then process it

    print('Sold!')
    tickets_remaining -= int(tickets_wanted)
    print('{} tickets are remaining!'.format(tickets_remaining))
  else:
    print('No problem! Thank you {}!'.format(user_name))

print('I am sorry. We are all out of tickets!')```

1 Answer

boi
boi
14,242 Points

It seems you are referring to the invalid literal for int() with base 10: which is a built-in system feature, it is the systems' way of handling this error, which is when you pass in a str instead of an int.

There is the same question possed by Hydar Omar under the title Getting a weird message in my error response followed by a detailed answer by Steven Parker, you should check that out in case you need more details.

Thank you @boi I will check it out!