I’m a beginner at python. I’m trying to make a simple program that allows you to enter your name and then it will just print your name.
This is my code.
name = input("Enter your name: ")
print name
Simple, should work. Works on any of the try me sections on python.org but for some reason, on my desktop and on my laptop I get the same error.
>>>
Enter your name: Toast
Traceback (most recent call last):
File "C:/Users/Shepard/Desktop/practice.py", line 1, in <module>
name = str(input("Enter your name: "))
File "<string>", line 1, in <module>
NameError: name 'Toast' is not defined
I saw that and I tried:
name = str(input("Enter your name: "))
print name
Same error persists. The only time it works, is when the user is asked for their name, and the user types in, for example, “Toast” in parenthesis.
What’s going on here?
You should be using
raw_input, instead ofinputsince you’re on Python2.X instead of Python3.XHere’s the docs for Python2’s raw_input and Python3’s input for comparison, along with the PEP 3111 (Python Enhancement Proposal) responsible for the change between the two versions, in order to better understand why the change was made.