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

Moses Gangipogu
Moses Gangipogu
3,772 Points

NameError: name ' ' is not defined

moses@moses-G41M-Combo:~/python$ cat lumberjack.py name = input("whats your name? ")

if name == "moses": print(name + " is a moses and he is OK") else: print(name + " he is NOT moses ")

moses@moses-G41M-Combo:~/python$ python lumberjack.py whats your name? moses Traceback (most recent call last): File "lumberjack.py", line 1, in <module> name = input("whats your name? ") File "<string>", line 1, in <module> NameError: name 'moses' is not defined

3 Answers

Sean May
Sean May
9,145 Points

Part of this may be what the challenge is looking for. Instead of using (name + "....string..."), you should be using the format string function, so, like this:

("{} is a lumberjack and {} is OK".format(name, name)

Moses Gangipogu
Moses Gangipogu
3,772 Points

got it working by change this line

name = input("whats your name? ")

to

name = raw_input("whats your name? ")

but i am not sure why this happens

Julio Gonzalez
Julio Gonzalez
673 Points

If you're on a Mac make sure you are using the right Python version 3.4 otherwise you will get this error. ( note: most Macs come with I found 2.7 installed to begin this course you must upgrade to 3.4 ) https://www.python.org/ftp/python/3.4.3/python-3.4.3-macosx10.6.pkg