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)
![Windy Huynh Lu](https://secure.gravatar.com/avatar/200656099815c3e83495a0fc65e950cb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Windy Huynh Lu
1,003 PointsHELP PLEASE!
I was positive that my code is the same as Craig's but the valueError isn't running correctly. Also it still doesn't understand that there are only 100 tickets left. Please, help!
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} remaining tickets available.".format(tickets_remaining))
name = input("What is your name? ")
num_tickets = input("How many tickets would you like to purchase, {}? ".format(name))
# Expect a ValueError to happen and handle it appropriately...remember to test it out!
try:
num_tickets = int(num_tickets)
# Raise a ValueError if the request is for more tickets than are available
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:
total = num_tickets * TICKET_PRICE
print("The total due is ${}.".format(total))
confirmation = input("Would you like to proceed? (Y/N) ")
if confirmation.lower() == "y":
# TODO: Gather credit card information and process it.
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("Thank you anyways, {}.".format(name))
print("I'm sorry, {}. All tickets are sold out!!! :[ ".format(name))
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI tried it and got this:
There are 100 remaining tickets available.
What is your name? Sam
How many tickets would you like to purchase, Sam? 4
The total due is $40.
Would you like to proceed? (Y/N) y
SOLD!
There are 96 remaining tickets available.
What is your name? Joe
How many tickets would you like to purchase, Joe? two
Oh no, we ran into an issue. invalid literal for int() with base 10: 'two'. Please try again
There are 96 remaining tickets available.
That seems to be correct operation, both in counting down the tickets and handling the ValueError. Does it do something different for you?
Windy Huynh Lu
1,003 PointsWindy Huynh Lu
1,003 PointsI think it might have been a glitch. It didn't run correctly yesterday. I switched out to a different computer, and it's working properly again. That was very weird. Thank you so much for your response, Steven. I really really appreciate it!