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)
![Alok Yadav](https://secure.gravatar.com/avatar/4119c0ef2d3f08a9ef2e5b97f4a8d608?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Alok Yadav
1,023 PointsCan someone point out my error in this code?
This is the part in the video where he asks to make an exception for the ValueError. I kind of Frankensteined this but it works well until the end, where it automatically prints "We're sorry! All the tickets have sold out!" even when that's not true.
Thanks in advance.
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining for sale.".format(tickets_remaining))
user_name = input("\nHello! What is your name? ")
while True:
ticket_number = input("Hello {}! How many tickets would you like to purchase? ".format(user_name))
# Expect a ValueError to happen and handle it appropriately.
try:
total_price = int(ticket_number) * TICKET_PRICE
print("\nYour total will be ${}.".format(total_price))
break
except ValueError:
print('\nOops! Please enter your response in numerals.\n')
continue
proceed = input("Would you like to confirm your sale of {} tickets for ${}? Y/N ".format(ticket_number, total_price))
if proceed.lower() == "y":
print("\nAwesome! Your tickets have been sold!\n")
tickets_remaining -= int(ticket_number)
break
#TODO: Gather and process CC information.
else:
print("\nNo problem! Let's try again.\n")
continue
print("We're sorry! All the tickets have sold out.")
2 Answers
![jb30](https://secure.gravatar.com/avatar/681668d7cc4c5486851384a0feddda37?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
jb30
44,806 Points proceed = input("Would you like to confirm your sale of {} tickets for ${}? Y/N ".format(ticket_number, total_price))
if proceed.lower() == "y":
print("\nAwesome! Your tickets have been sold!\n")
tickets_remaining -= int(ticket_number)
break
When you use break
here, you are breaking out of the while loop formed at while tickets_remaining >= 1:
, so your program does not recheck the condition before continuing below the while loop. If you comment out or remove the break
from this section, the while loop will continue to run and will check if tickets_remaining >= 1
.
![Tanzila Rafeeq](https://secure.gravatar.com/avatar/cf52c7768a1f4d12f96e8ad43b0a51c9?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tanzila Rafeeq
2,936 Pointsyou need to put away break, and you don't need continue
![Alok Yadav](https://secure.gravatar.com/avatar/4119c0ef2d3f08a9ef2e5b97f4a8d608?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Alok Yadav
1,023 PointsThanks for responding, I appreciate it! Follow up question: I enter continue there because I want it to loop back (is that the right term?) to the point where they enter the number of tickets. Don't I need to put a continue for that to happen?
Alok Yadav
1,023 PointsAlok Yadav
1,023 PointsThanks so much for answering this!!