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

Lauren O'Brien
Lauren O'Brien
7,420 Points

python in terminal requires "" for response to input() prompt

Hi Kenneth,

I was trying to follow the tutorial using the native terminal / python in osx -- if i answer the prompt without enclosing my response in quotes i get the following error:

What's your name? Lauren Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'Lauren' is not defined

with quotes, no problem:

What's your name? "Lauren" Lauren is a lumberjack and he/she's OK!

Any idea why this might be? Is there a module or something I need to add to the native python?

Thanks for your help!

3 Answers

Joseph Kato
Joseph Kato
35,340 Points

Are you using Python 2.x by any chance?

In Python 2, input() performs an eval() on the entered values, which would explain the NameError. To get around this, you could use raw_input(), or you could switch to Python 3 and continue to use input().

Lauren O'Brien
Lauren O'Brien
7,420 Points

Aha! Thank you! I had simply typed "python" from the terminal prompt instead of "python3". Works like a charm now.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Yeah, as soon as I saw that NameError, I knew it was a Python 2 problem. Good catch, Joseph Kato!

If you do want to write this in Python 2 instead of 3, use raw_input() instead of input().