Python Forum

Full Version: My 1st Program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need help in this simple program! I don't know why I'm getting this error! I'm new to python!

This is what I typed:

print ('WHAT IS YOUR NAME?')
name = input()
print (name)
This was the result:

Output:
WHAT IS YOUR NAME? kevin
Error:
Traceback (most recent call last): File "C:/Python27/pye.py", line 2, in <module> name = input() File "<string>", line 1, in <module> NameError: name 'kevin' is not defined
WHAT IS WRONG HERE?
Simple answer - this code is intended to run on python3 and you are running it on python2. As you are new to python - install python3 and use it, not python2. Support for python2 will end soon.

The reason behind the problem - in python2 one should use raw_input() instead of input(). In python2 input() evaluates the user input as if it is valid python code, while raw_input() just returns user input as string.
In python3 input() returns user input as string, so it is equivalent to raw_input() in python2.