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

Error in Code for LUMBERJACK EXERCISE

Here is the code I'm using:

name = input("What's your name?")

if name == "Andrew" :
    print("{} is a lumberjack and he's okay!".format(name))
    else:
        print("{} sleeps all night and {} works all day!".format(name, name))

Here is the error that I'm receiving:

treehouse:~/workspace$ python lumberjacked.py                                                                                                                                      
  File "lumberjacked.py", line 5                                                                                                                                                   
    else:                                                                                                                                                                          
       ^                                                                                                                                                                           
SyntaxError: invalid syntax    

What am I doing wrong???

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

The else statement and it's print are indented too far:

name = input("What's your name?")

if name == "Andrew" :
    print("{} is a lumberjack and he's okay!".format(name))
else:
    print("{} sleeps all night and {} works all day!".format(name, name))

Also, it looks like you are using TAB instead of spaces. It is recommended to use 4-space indentation.

Thanks Chris Freeman. I don't believe I intentionally did that...but hey that's how you learn. I will give this a try & let you know how it works!

Thanks!