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:

try:
    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)) 
else:    
    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.
        print("SOLD!")
        tickets_remaining = tickets_remaining - tickets_requested
    else:
        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: