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 (Retired) Ins & Outs String Concatenation

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

SyntaxError: keyword can't be an expression

I've typed in the code below and it comes up with the error "SyntaxError: keyword can't be an expression" and it seems to be indicating at the first name in the print function in else:.

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

if name == "Kenneth": print(name + " is a lumberjack and he's OK!")

else: print(name + " sleeps all night and " + name = " works all day!")

Another thing is that the code doesn't seem to have the same colour indication as was shown in the video, the " " statements are all in green as opposed to blue.

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

The line below is wrong. You are using "=" sign as if you were assigning name to a new string within the print function. Doesn't work that way.

else: print(name + " sleeps all night and " + name = " works all day!")

Try it like this.

You need to use name as a variable and put the = as part of the String.

else: print(name + " sleeps all night and " + name + "= works all day!")

This worked for me in the interpreter

>>> name = input("What's your name? ")
What's your name? Ryan
>>> if name == "Kenneth": print(name + " is a lumberjack and he's OK!")
... else: print(name + " sleeps all night and " + name + "= works all day!")
...
Ryan sleeps all night and Ryan= works all day!
>>>

Does this make sense? If not please let me know and I can try to explain it further.

Thanks!