Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Cleaner Code Through Refactoring

keep 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
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

Hey 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!