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

Maximilian Platz
Maximilian Platz
1,536 Points

Program does not raise ValueError

My code doesn´t put out the string "There are only ... tickets remaining" in line 19. I can´t find my mistake. Here´s my code:

    tickets_requested = int(tickets_requested)

    if tickets_requested > tickets_remaining:
        raise ValueError ("There are only {} tickets remaining".format(tickets_remaining))
except ValueError as err:
    print("Oh no we ran into an issue, please try again!".format(err)) 
    amount_due = calculate_price(tickets_requested)
    print("The total due is ${}.".format(amount_due))
    should_proceed = input("Would you like to proceed? (Y/N) ")
    if should_proceed.lower() == "y":
        #TODO: Gather credit card information and process it.
        tickets_remaining = tickets_remaining - tickets_requested
        print("Thank you {}! ".format(user_name))

1 Answer

It should say:

raise ValueError:
   print("There are only {} tickets remaining".format(tickets_remaining))
except ValueError as err: