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

Masterticket.py-my_code_never_warns_the_user_that_the_price_is_too_much

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("How many tickets would you like, {}? ".format(name)) # Expect a ValueError to happen and handle it appropriately...remember to test it out! try: #raise ValueError: num_tickets = int(num_tickets) # Raise a ValueError if the request is for more tickets than are avaible if num_tickets >= tickets_remaining: raise ValueError("There are only {} tickets remaining".format(tickets_remaining)) except ValueError as Err: # Include the error text in the output print("Oh no, we ran into an issue. {}. Please try again".format(Err)) else: amount_due = num_tickets * TICKET_PRICE print("The total due is ${}".format(amount_due)) should_proceed = input("Do you want to proceed? Y/N ") if should_proceed.lower() == "y": # TODO": Gather credit card information and process it. print("SOLD") tickets_remaining -= num_tickets else: print ("Thank you anyways, {}!".format(name)) print("Sorry the tickets are all sold out!!!")

boi
boi
14,242 Points

Luke, Your question's format stressed me to the core. You should definitely learn to use format properly, start by watching this.

2 Answers

Steven Parker
Steven Parker
231,248 Points

I'm not sure why you would be expecting such a warning, since there's nothing in this code that would test for a limit on the price. I guess you can charge whatever you want! :see_no_evil:

I'm trying to raising a value error when the number of tickets exceed 100. When I type a number over 100 tickets, it treats it like it isn't too much:

"The total is due $....... Do you want to proceed Y/N?" Then it says to the user that the tickets it's SOLD, and it's out of tickets.

Steven Parker
Steven Parker
231,248 Points

This might be the result of an indentation issue, but we can't check it in unformatted code. Try editing the code part of the question using Markdown formatting to preserve the original appearance.

Thanks for both of your response. I will look into it that very soon. Thankfully, I retyped the whole lesson, from reviewing another person's attempt,(with a couple of different variable name changes and values) and it works perfectly now.