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 trialJan Habermann
463 PointsSyntaxError: Invalid Syntax
This is my code
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
name = input("What is your name? ")
print("Welcome {}!".format(name))
print("There are {} tickets remaining.".format(tickets_remaining))
try:
order_amount = int(input("How many of those would you like," + name + "? "))
if order_amount > tickets_remaining:
raise ValueError ("Sorry there are only {} tickets left".format(tickets_remaining)
except ValueError as err:
print("Sorry, we ran into an issure. Please try again. {}.".format(err))
else:
order_price = order_amount*TICKET_PRICE
print ("That comes up to $", order_price)
ask_proceed = input("Do you want to proceed? Y/N ")
if ask_proceed.lower() == "y":
print("SOLD!!! Have fun " + name)
tickets_remaining -= order_amount
else:
print("Thank you anyways {} and have a nice day".format(name))
print("Sorry that's all folks!! ")
I get a Syntax Error pointing to the e in except and I have no idea what is wrong, try and except ar indetned the same amount so that can't be it
2 Answers
Steven Parker
231,198 PointsWhen something needed is left off, the error often points to the next character after the problem.
In this case, the parentheses on the previous line are unbalanced (the function still needs a closing parenthesis).
Jan Habermann
463 PointsTrue, I missed that, seems like I thought I neededd to allignt it with the "if" for some reason
thanks a lot
Jan Habermann
463 PointsJan Habermann
463 PointsThanks a lot, didn't know that sometimes the next character get pointet to.
Now I get a syntax error on the else for wome reason though
Steven Parker
231,198 PointsSteven Parker
231,198 PointsThe "else" is indented too far and doesn't line up with the "try" and "except".