-2

I'm a Python newbie and I get the following error for the code...

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

Output:

G:\Code\Python>UserInput.py
What's your name? Jeremy
Traceback (most recent call last):
  File "G:\Code\Python\UserInput.py", line 3, in <module>
    name = input("What's your name? ")
  File "<string>", line 1, in <module>
NameError: name 'Jeremy' is not defined

The code gets executed only if I replace the input() as raw_input... How do I get it to display the message just by including the input()? I get that it has got something to do with the Python Interpreter versions (I've got both python27 and python34 installed). How do I go on about that??

gRao92
  • 91
  • 1
  • 8
  • Why do you want it to work with only `input`? To rephrase, what is the problem with using `raw_input()` ? – Anand S Kumar Aug 22 '15 at 06:47
  • If you are lazy to type 4 extra characters (`'raw_'`) , then you should only use python 3 instead of 2. – Anand S Kumar Aug 22 '15 at 06:54
  • yeah... how do I set my default interpreter to python 3? I tried changing the path in the environment variables but nothing seems effective. – gRao92 Aug 22 '15 at 06:59

1 Answers1

1

You shouldn't be using input, it is equivalent to eval(raw_input(prompt)) which will try to execute your input.

https://docs.python.org/2/library/functions.html#input

Use raw_input instead.

veggie1
  • 717
  • 3
  • 12