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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Temi Folorunsho](https://secure.gravatar.com/avatar/d5a5ac4c9875f705c2bd6f2cdf5aa1a2?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Temi Folorunsho
2,849 PointsBranch and loop on tickets_remaining exercise
In the while loop, the codes still runs if the num_tickets is zero, is it supposed to run after we already specified it as >=1 ?
TICKET_PRICE = 10
tickets_remaining = 100
Run this code continuosly until we run out of tickets
while tickets_remaining >= 1:
# Output how many tickets are remaining using the tickets_remaining variable.
print("There are {} tickets left".format(tickets_remaining))
# Gather the user's name and assign it to a new variable.
name = input("What is your name? ")
# Prompt the user by name and ask how many tickets they would like.
number_of_tickets = int(input("Hey {}, how many tickets would you like?".format(name)))
# Calculate the price(number of tickets multiplied by the ticket_price) and assign it to variable
price = number_of_tickets * TICKET_PRICE
# Output the price to the screen
print("The ticket costs ${}".format(price))
# Prompt user if they want to proceed Y/N?
should_proceed = input("Do you want to proceed? Y/N ".format(name))
# if they want to proceed
if should_proceed.lower() == "y":
# print out to the screen SOLD! to confirm purchase
print("SOLD!")
# and the decreament of the tickets remaining by the number of tickets purchased
tickets_remaining -= number_of_tickets
# Otherwise....
else:
# Thank them by name
print("Thank you {} for patronizing us".format(name))
Notify the user that tickets are sold out
print("Hey {} the tickets are sold out".format(name))
1 Answer
![christopher diaz](https://secure.gravatar.com/avatar/4023b45fcb3d6f410df35ca77d9db4f8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
christopher diaz
2,364 PointsHey Temi,
Looking over your code, I noticed you did not add a couple of items. I am pasting your code and including the item that I am referring to, as well as commenting on them with my name next to it.
TICKET_PRICE = 10 tickets_remaining = 100
To trigger the remaining tickets available, you need the while loop - Chris Diaz
while tickets_remaining >= 1:
# The code in line 7 outputs the latest number of tickets available - Chris Diaz
print("There are {} tickets remaining".format(tickets_remaining))
# Gather the user's name and assign it to a new variable.
name = input("What is your name? ")
# Prompt the user by name and ask how many tickets they would like.
number_of_tickets = int(input("Hey {}, how many tickets would you like?".format(name)))
# Calculate the price(number of tickets multiplied by the ticket_price) and assign it to variable
price = number_of_tickets * TICKET_PRICE
# Output the price to the screen
print("The ticket costs ${}".format(price))
# Prompt user if they want to proceed Y/N?
should_proceed = input("Do you want to proceed? Y/N ".format(name))
# if they want to proceed
if should_proceed.lower() == "y":
# Print out to the screen SOLD! to confirm purchase
print("SOLD!")
# and the decrement of the tickets remaining by the number of tickets purchased
tickets_remaining -= number_of_tickets
# Otherwise....
else:
# Thank them by name
print("Thank you {} for patronizing us".format(name))
This gets triggered once the application recognizes it no longer has tickets - Chris Diaz
print("Sorry the tickets are all sold out!!!")
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherHi! Can you share your code?