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

Having issues running the script from the lesson video. I'm typing exactly what is being typed in the video.

I tried running a script from the video. I keep getting a SyntaxError: invalid syntax and keep pointing to the a "s" right before .py

Here is my script. I called the file functions.py

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

hows_the_parrot()

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

lumberjack("Joshua")

2 Answers

Hi Joshua,

The Syntax error is pointing to the use of single quote ' to open the string and double quotes " to close it - 'Joshua"

Also the .format() is expecting two values. Even if they are the same you'll need to reference them twice.

Lastly I copied yours and tried to run it directly. It was only after putting new statements on new lines that I didn't hit the syntax error. So at the end of a statement put the next statement on a new line with correct indentation. e.g.

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

Good luck mate!

I made the corrections bellow and still ended up with the same error, I am not sure if I am getting the code format done properly or if there is something going on with workspace. I also even tried formatting with the print function on the same line as else. Example: else: print("{} sleeps all night and {} works all day!".format(name, name))

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

hows_the_parrot()

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

lumberjack("Joshua")

I've tried working on it and solving the issue, maybe I am over looking something or maybe misunderstanding something.

I actually figured out the tiny issue, the corrections you showed me worked and the script ran. I just needed to click on file and save. Thank you for the help.

no problem mate, glad you got it working!