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 trial

Python Python Basics All Together Now Handle Exceptions

Julieta Dalla Pozza
Julieta Dalla Pozza
4,337 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 68,441 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!!!