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)
![Héctor Gómez](https://secure.gravatar.com/avatar/08218438725d7f93df8b3233ce1e013e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Héctor Gómez
951 PointsWhen doing the "ValueError as err" it doesn't solve the "How many ticket do you want? Blue" error we solved earlier
How can we solve the Blue error again?
6 Answers
![Ian Salmon](https://secure.gravatar.com/avatar/677542ee9335f0575b87fd0ccbf74a02?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ian Salmon
Courses Plus Student 10,687 PointsI've seen this problem across the forums. You need another ValueError statement to specifically address input that isn't a number. The isdigit() method is great for this.
Add an 'if' statement directly under your 'try'. Something like (sorry for no syntax formatting).
try: if not tickets_requested.isdigit(): raise ValueError("That isn't a number. Please choose between 1 and {}.".format(tickets_remaining))
tickets_requested = int(tickets_requested)
if tickets_requested > tickets_remaining: ......
Let me know if you're still having trouble!
![Elaine Youngman](https://secure.gravatar.com/avatar/a7a6290d9594cbc4b187276664fea12c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Elaine Youngman
401 PointsTook me a bit to figure out how to tweak everything, but Ian's solution works perfectly!
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >=1:
print("There are {} tickets available.".format(tickets_remaining))
name = input("Hello! Welcome to the Python extravaganza. What is your name? ")
try:
number_requested = input("How many tickets would you like to buy, {}? ".format(name))
if not number_requested.isdigit():
raise ValueError("Please enter ticket request as a whole number.")
else:
number_requested = int(number_requested)
if number_requested > tickets_remaining:
raise ValueError("You have requested more tickets than we have!")
except ValueError as err:
print("Oops! Something has gone wrong. {} Try again.".format(err))
else:
total_price = number_requested * TICKET_PRICE
print("OK {}, the total for {} tickets is ${}.".format(name, number_requested, total_price))
confirm = input("Would you like to continue with the purchase? y/n ")
if confirm.lower() == "y":
#TODO: collect credit card information and charge
print("SOLD! Enjoy the show, {}.".format(name))
tickets_remaining -= number_requested
else:
print("Sorry to see you go {}! Have a nice day.".format(name))
print("This show is sold out!")
![jesus perez](https://secure.gravatar.com/avatar/619f6576ce8334025094a10894f0af0e?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
jesus perez
832 Pointsworked better, thx.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsIt should still handle that situation, the only difference is that the message will now include more information.
![Johanna Gold](https://secure.gravatar.com/avatar/d0a0a0cfeb8bee59bf9b8467d3b44831?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Johanna Gold
615 PointsSteven, does that not defeat the purpose of having friendly error messages? This example seems like a bad fix. I am having some trouble understanding what Ian is advising, Any clarification on that would be appreciated.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI agree, this particular example seems to focus only on demonstrating the mechanism and doesn't do much to make the messages more "user-friendly". But once you understand how the basic mechanism works, you can certainly use the same technique to construct a much more friendly response in your own code.
![zoltans](https://secure.gravatar.com/avatar/040c7037f42ed24b416c9aa5f4faefed?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
zoltans
2,547 PointsI'm just wondering, why the "invalid literal for int() with base 10:" didn't come up in Craig's code. Can anyone elaborate on that? thanks
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsBut it did, at about 3:30 in the video when he entered "blue" instead of a number.
![zoltans](https://secure.gravatar.com/avatar/040c7037f42ed24b416c9aa5f4faefed?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
zoltans
2,547 PointsCould you lease have a look if you can find something different from Craig's here, because I still get the "invalid literal for int() with base 10:" error message, alongside the user friendly message:
Please enter your full name: Rob
How many tickets would you like to purchase, Rob? blue
Oh, no...That's not a valid value. Please, try again...
invalid literal for int() with base 10: 'blue'
There are 100 tickets remaining.
Thank you
num_tickets = input("How many tickets would you like to purchase, {}? ".format(name))
try:
num_tickets = int(num_tickets)
if num_tickets > tickets_remaining:
raise ValueError("There are only {} tickets remaining..."
.format(tickets_remaining))
except ValueError as err:
print("Oh, no...That's not a valid value. Please, try again...")
print("{}".format(err))
else:
amount_due = calculate_price(num_tickets)
print("The total due is £{}.".format(amount_due))
conf = input("Would you like to proceed? Y/N: ")
if conf.lower() == "y":
#TODO: gather credit card information and process it
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("Thank you for your interest {}!\nHave a nice day!".format(name))
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 Points print("Oh, no...That's not a valid value. Please, try again...")
# print("{}".format(err)) <-- Craig's code does not have this line
For future issues, please always start a fresh question instead of asking a question as an "answer" to another question!
![zoltans](https://secure.gravatar.com/avatar/040c7037f42ed24b416c9aa5f4faefed?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
zoltans
2,547 PointsOh, got it! Thanks a lot, I have spent such a long time on this. Sure, I'll start a fresh question next time . Still new to this.
jesus perez
832 Pointsjesus perez
832 Pointsgreat addition!