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 trialAdam Marasli-Zaade
2,966 PointsWhy 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.
4 Answers
Vidhya Sagar
1,568 PointsMissed 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
1,568 PointsDamn,man .How much items will you post it for Christ sake.CHECK THE PARANTHESIS FOR LAST PRINT.
Adam Marasli-Zaade
2,966 Points???
Nichelle Segar
9,857 PointsIn the terminal, type:
from functions import lumberjack
Brian Hudson
14,785 PointsWhat 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.
Vidhya Sagar
1,568 PointsVidhya Sagar
1,568 PointsYou 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")