## 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.

# When entering amount of tickets wanted, it loops back into the while loop making it impossible to complete the purchase

import time

TICKET_PRICE = 10

tickets_remaining = 100
tickets_remaining = int(tickets_remaining)
while tickets_remaining > 0:
print("There are {} tickets remaining.".format(tickets_remaining))

name = input("What is your name?")
tickets_requested = input("Hello {}, how many tickets would you like to buy?".format(name))
#Expect a ValueError to happen and handle it
try:
tickets_requested = int(tickets_requested)
if tickets_requested > tickets_remaining:
raise ValueError("There are only {} tickets remaining".format(tickets_remaining))
except ValueError as err:
print("Oh no, Please make sure that the value you entered was a number, try again.")
else:
if tickets_requested > 1:
ticket = "tickets"
else:
ticket = "ticket"

total_cost = tickets_requested * TICKET_PRICE
total_cost = str(total_cost)
#output price to screen
print("The total cost for {} {}, is \${}".format(tickets_requested,ticket,total_cost))

proceed = input("Would you like to proceed? Y/N")
if proceed.lower() == "y":
print("SOLD! Purchase confirmed")
tickets_remaining -= tickets_requested
else:
print("Thank you {} for your time. Goodbye".format(name))

print("Sorry, All the tickets are sold out.")