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 Error

My code is

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

if name == "Jake":
    print("{} is a lumberjack and he is OK!".format(name))
else:
    print(" {} sleeps all day and {} works all day!".format(name, name))

The terminal response to my input "What is your name?" is:

Traceback (most recent call last): File "lumberjack.py", line 1, in <module> name = input("What's your name? ") File "<string>", line 1, in <module> NameError: name 'j' is not defined

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

If running Python 2, when using input() the received data is interpreted. To work around this, wrap quotes around your input "j". You could also change to raw_input() which casts the data as a string.

Otherwise, run Python3 where input() assumes data is a string.

Awesome thank you ! Do you have any how to install Python 3.5 on Ubuntu anyways?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

Python 3.5 will be harder to get as it's not in the distribution libraries for Ubuntu yet. Unless there is a screaming need for 3.5, Python 3.4 will work fine (it's what i run).

$ sudo apt-get install python3

If you insist on 3.5, check this links: