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

Natalie Heyde
Natalie Heyde
1,736 Points

Syntax 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!
        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))
        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.
            tickets_remaining -= num_tickets
            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
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

Hey 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
Natalie Heyde
1,736 Points

Thank you so much, Mel!