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

Adam Saby
Adam Saby
3,376 Points

Traceback and index errors when following along with the video activity

I can't figure out how to paste images, or code from the workspaces console in here, but I having difficulty following along to the activity even though my code matches the instructor, when I call the python functions.py file, I am getting strange results. Here is my code:

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

hows_the_parrot()

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

lumberjack("Kenneth")

formatted code

2 Answers

Hi Adam,

In your else statement, you have 2 placeholders in your string so you need to pass 2 arguments to the format method.

Kenneth adds the name twice around 5:50 in the video.

.format(name, name)

Also, this won't produce any errors but you have a problem with the logic.

if name.lower() == 'Kenneth':

You have to make 'Kenneth' all lowercase or it will never be true.

Adam Saby
Adam Saby
3,376 Points

thanks so much, that worked!