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

Gary Gibson
Gary Gibson
5,011 Points

Error Despite Copying Exactly

Here is my code:

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

lumberjack("gary")

And here is the error I'm getting in the shell:

treehouse:~/workspace$ python functions.py                                 
  File "functions.py", line 10                                             
    print("{} sleeps all night and {} works all day!".format(name))        
                                                                  ^        
TabError: inconsistent use of tabs and spaces in indentation

[MOD: added markdown code block formating -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

Your first print uses 8 spaces, your second print uses 2 tabs. Best to use same for both, and best to use spaces

Roberto Núñez
Roberto Núñez
4,256 Points

Jajaja I think is about the fact that out dear professor forgot to put .format(name,name) so after half an hour trying to make it work, I give up and press play... then he corrects it. Lesson learned wait until it works for HIM first. Learned a lot about inputing and playing with inputs in the process LOL.

Chris Freeman
Chris Freeman
Treehouse Moderator 67,989 Points

Yes, it's best to wait for the working version. Treehouse has received much positive feedback on seeing the instructors make and correct basic mistakes in their code. Many lessons are in the mistakes.