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

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

TICKET_PRICE = 10

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))
try:
    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))
else:
    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" :
        print("SOLD!")
        tickets_remaining -= num_tickets      
    else:
              print("thanks anyway!",format(name))

print("Sorry all Sold")

2 Answers

Steven Parker
Steven Parker
231,172 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!