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 trialNatalie Heyde
1,736 PointsSyntax error on line 23 for except statement
I was wondering if you could help explain why I keep getting the SyntaxError: invalid syntax on line 23 (the "except ValueError as err" line)? I keep re-typing it in thinking there is a spacing issue/typo, but I can't seem to figure out what is triggering the error. I saw a similar question pertaining to this, but I thought I had fixed the indentation issue?
Edit: Thank you, Steven! Now I can post the example.
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:
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, we ran into an issue. {}. Please try again.".format(err))
else:
amount_due = calculate_price(num_tickets)
print("Your total will be ${}.".format(amount_due))
interested = input("Would you like to proceed with your purchase?\nEnter (Y/N) ")
if interested.lower() == "y":
# TODO: Gather credit card information and process it.
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("Thank you anyway, {}!".format(name))
print("So sorry, {}, but there are no tickets remaining.".format(name))
Here is the link as well: https://w.trhou.se/qj35skyqzn
1 Answer
Mel Rumsey
Treehouse ModeratorHey there Natalie Heyde ! I took a look at your snapshot. Sometimes if you don't see an error on the line that it says, it could be something in the line above it. In line 22 there is a missing closing parenthesis on your raise ValueError()
. This happens all the time, but if you ever get stuck, try checking out the line about the error.
Natalie Heyde
1,736 PointsNatalie Heyde
1,736 PointsThank you so much, Mel!