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 Handle Exceptions

Julieta Dalla Pozza
Julieta Dalla Pozza
3,104 Points

IF invalid syntax

Hello i have this code, and i don't get what i am doing wrong. Keep rising an invalid syntax error

while tickets_remaining >= 1: 
    print("There are {} tickets remaining.".format(tickets_remaining))
    name = input("Morning there, what is your name?  ")
    ask_tickets = input("How many tickets do yo need, {}?  " .format(name))
    #calculate the price (number of tickets multiplied by the price) and assign it to a variable
    try:
        ask_tickets = int(ask_tickets)
        #raise a value error if the request is for more tickets than are available
    if ask_tickets > tickets_remaining:
        raise ValueError print("Sorry there are only {}" .format(tickets_remaining))

ERROR :
  File "tickets.py", line 14
    if ask_tickets > tickets_remaining:
    ^
SyntaxError: invalid syntax

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,736 Points

Hey Julieta Dalla Pozza,

It’s not the if. The try: block is missing an associated except block.

Post back if you need more help. Good luck!!!