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 trialdavid Keller
Python Development Techdegree Student 373 Pointskeep getting a syntax error by line 23
I keep getting a syntax error, right at except Valueerror as err any ideas why?
SIR_CHARGE = 2
TICKET_PRICE = 10
tickets_remaining = 100
def calculate_price(num_tickets):
return ( TICKET_PRICE * num_tickets) + SIR_CHARGE
while num_tickets >= 1:
print("There are {} tickets remaining.".format(tickets_remaining))
# Gather the user's name and assign it to a new variable
name = input("What is your name? ")
# Prompt the user by name and ask how many tickets they would like
num_tickets = input("How many tickets would you like, {}? ".format(name))
try:
num_tickets = int(num_tickets)
# Calculate the price (number of tickets multiplied by the price) and assign it to a variable
if num_tickets > tickets_remaining:
raise ValueError("there are only {} ".format(tickets_remaining))
except ValueError as err:
print(" ok no prop man {}".format("err"))
amount_due = num_tickets * TICKET_PRICE
# Output the price to the screen
print("The total due is ${}".format(amount_due))
[MOD: added ```python formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsHey david Keller, the except
statement is indented too far. It should align with the try
statement above it.
Post back if you need more help. Good luck!