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)
![Amy Tomey](https://secure.gravatar.com/avatar/1a609d30362adcb9f565bd7f2c4932a7?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Amy Tomey
12,847 PointsTickets sold, then told the event is sold out?
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining.".format(tickets_remaining))
user_name = input("What is your name? ")
number_of_tickets = input("how many tickets would you like, {}? ".format(user_name))
#Expect ValueError and handle appropriately
try:
number_of_tickets = int(number_of_tickets)
#raise ValueError if the reqoest is for more tickets than are available
if number_of_tickets > tickets_remaining:
raise ValueError("There are only {} tickets left. Please try again.".format(tickets_remaining))
except ValueError as err:
# include error text in output
print("Oh no! We ran into an issue. {}. Please try again".format(err))
else:
total_cost = TICKET_PRICE * number_of_tickets
print("{}, the total for {} tickets is ${} dollars.".format(user_name, number_of_tickets, total_cost))
buy_them = input("{}, Do you want to complete your purchase? Enter Y/N ".format(user_name))
if buy_them.lower() == "y":
# TODO gather payment info and process it
print("{} tickets SOLD to {} for {}!" .format(number_of_tickets, user_name, total_cost))
tickets_remaining -= number_of_tickets
else:
print("Thank you, {}".format(user_name))
print("I'm sorry, {}. The event has sold out. :( There are no more tickets available.".format(user_name))
I got this: treehouse:~/workspace$ python masterticket.py
There are 100 tickets remaining.
What is your name? Amy
how many tickets would you like, Amy? 3
Amy, the total for 3 tickets is $30 dollars.
Amy, Do you want to complete your purchase? Enter Y/N y
3 tickets SOLD to Amy for 30!
I'm sorry, Amy. The event has sold out. :( There are no more tickets available.
There are 97 tickets remaining.
What is your name? Amy
how many tickets would you like, Amy? 8
Amy, the total for 8 tickets is $80 dollars.
Amy, Do you want to complete your purchase? Enter Y/N n
Thank you, Amy
I'm sorry, Amy. The event has sold out. :( There are no more tickets available.
There are 97 tickets remaining.
I'm a little confused. ...
1 Answer
![Jason Larson](https://uploads.teamtreehouse.com/production/profile-photos/11651180/micro_JLarson-Crop3.jpg)
Jason Larson
8,359 Pointsit looks like that print statement with the sold out message should be outside of your while, because the while is checking if the number of tickets is >= 1, so that last print statement doesn't make sense inside of the while.