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

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
218,639 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!