0

my code in Python

name = input('Name: ')
Name: Jeffrey

and my error

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

I have no idea what is going on here. I am using python 3.4.5 on a mac uploaded through pyenv install 3.4.5

  • 1
    Seems like you're using Python 2 still. Run `print(sys.version)` to see which python version is actually being used, you have to import `sys` first as well. – AliciaBytes Jan 12 '17 at 05:28

2 Answers2

1

It seems that you're still using Python2.x.

Because in Python3.x input will return a string,and you won't got this error.

If you're using Python2.x input function evaluates your input and tries to run the input as a Python expression.So if your input is a string ,you will got :

NameError: name 'xx' is not defined

Add this to your code and get your Python version.And you will see what's wrong with your code.

import sys
print(sys.version)

Hope this helps.

McGrady
  • 10,869
  • 13
  • 47
  • 69
0

use this :

name=raw_input('name : ')