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 (2015) Logic in Python Fully Functional

Why am I getting a syntax error ?

Hello, everybody :) Why am I getting a syntax error whilst I have followed the video instructions ?

def hows_the_parrot():
    print("he is pining for the fjords!")

hows_the_parrot()

def lumberjack(name):
    if name.lower() == 'kenneth':
       print("Keneth's a lumberjack and he's OK!")
    else:
       print("{} sleeps all night and {} works all day!".format(name, name)

lumberjack("Kenneth")

That's my code.

I run it and I get this :

File "functions.py", line 12
lumberjack("Kenneth")
^
SyntaxError: invalid syntax

Thanks in advance.

Vidhya Sagar
Vidhya Sagar
1,568 Points

You missed the brackers in print bro.In the else block ,you did"t close the brackets for print.Thats why.

Correct CODE: def hows_the_parrot(): print("he is pining for the fjords!")

hows_the_parrot()

def lumberjack(name): if name.lower() == 'kenneth': print("Keneth's a lumberjack and he's OK!") else: print("{} sleeps all night and {} works all day!".format(name, name))

lumberjack("Kenneth")

4 Answers

Vidhya Sagar
Vidhya Sagar
1,568 Points

Missed to close the brackets for print in Else block. def hows_the_parrot(): print("he is pining for the fjords!")

hows_the_parrot()

def lumberjack(name): if name.lower() == 'kenneth': print("Keneth's a lumberjack and he's OK!") else: print("{} sleeps all night and {} works all day!".format(name, name))

lumberjack("Kenneth")

Vidhya Sagar
Vidhya Sagar
1,568 Points

Damn,man .How much items will you post it for Christ sake.CHECK THE PARANTHESIS FOR LAST PRINT.

???

Nichelle Segar
Nichelle Segar
9,857 Points

In the terminal, type:

from functions import lumberjack

What they're trying to say is you just missed the closing parentheses in your last print statement:

else:
       print("{} sleeps all night and {} works all day!".format(name, name)) # <--- closing parenthesis right here 

lumberjack("Kenneth")

It's easier to see in markdown.