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 trialMichael Cronk
8,970 PointsCleaned up the Ticket Sale Project... Feedback for me
TICKET_PRICE = 10
SERVICE_FEE = 2
tickets = 100
def calculate_price(num_of_tickets):
return (num_of_tickets * TICKET_PRICE) + SERVICE_FEE
while tickets != 0:
user_name = input("What is your name? ")
if user_name == "":
print("You can't leave the name blank, please try again.")
continue
print("There are {} tickets left".format(tickets))
print("Tickets are ${} each".format(TICKET_PRICE))
try:
amount_of_tickets = int(
input("How many tickets would you like to purchase, {}? ".format(user_name.capitalize())))
if amount_of_tickets >= 101:
print("There are only {} tickets... Please try again.".format(
tickets))
continue
except ValueError:
print("That is an invalid entry, try again.")
else:
amount_due = calculate_price(amount_of_tickets)
print("There is a service fee of ${}.".format(SERVICE_FEE))
assure = input(
"You would like to buy {} tickets for ${}? Y/N: ".format(amount_of_tickets, amount_due)).capitalize()
if amount_of_tickets > tickets:
print("There are only {} tickets left... Please try again.".format(
tickets))
elif assure == "Y":
print("You have bought {} tickets for ${}".format(
amount_of_tickets, amount_due))
tickets -= amount_of_tickets
elif assure == "N":
print(
"Well thanks for visiting the shop {}, have a good day!".format(user_name.capitalize()))
exit()
else:
print("That is an invalid answer")
if tickets == 0:
print("We are sold out... Thank you.")
Michael Cronk
8,970 PointsMichael Cronk
8,970 PointsThank you!