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

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: