Python Python Basics All Together Now Handle Exceptions

Ticket Remaining problem

Hi, Im completely stuck in one place: console showing "There are tickets_remaining tickets remaining. " I cant find any issue of that,

here is a code


tickets_remaining = 100

while tickets_remaining >= 1:

print("There are {} tickets remaining.".format("tickets_remaining"))
name = input("What is your name?   ")
num_tickets = input("Ammount of tickets  {}?   ".format(name))
    num_tickets = int(num_tickets)
    if num_tickets > tickets_remaining:
        raise ValueError("There are only {} tickets left".format(tickets_remaining))
except ValueError as err:
    print("Wrong value.{} Try again".format(err))
    ammount_due = num_tickets * TICKET_PRICE
    print("Total price is {}$".format(ammount_due))
    proceed = input("Would you like proceed?   Y/N")
    if proceed.lower() == "y" :
        tickets_remaining -= num_tickets      
              print("thanks anyway!",format(name))

print("Sorry all Sold")

2 Answers

Steven Parker
Steven Parker
177,538 Points

The cause is this line:

    print("There are {} tickets remaining.".format("tickets_remaining"))

Because of the quotes around "tickets_remaining", it is taken as a literal string and used to replace the token (the "{}") in the original string.

If you want to display the value of the varible named tickets_remaining, don't put quotes around it.

thanks a lot!