# NameError: name 'andrew' is not defined

I am new to python. When running the script below, I get this:

# Enter name: andrew
# Traceback (most recent call last):
  # File "test_python.py", line 7, in <module>
    # name = input("Enter name: ")
  # File "<string>", line 1, in <module>
# NameError: name 'andrew' is not defined
#! /usr/bin/python2
#import math
# Python 2.7.17 is version installed
# On 10/4/22 I installed version Python 3.10.7
 

name = input("Enter name: ")
age = input("Enter age: ")

print("data_type of name: ", type(name))
print("data_type of age: ", type(age))

Thanks for any help.

In Python 2, which is what you’re using, input accepts text and then evals it. It’s equivalent to eval(raw_input()).
If you want the script to use Python 3, change the shebang line to:

#! /usr/bin/python3

I made that change. I still get the same error.

I think it is using python 2.7 instead of the newer 3.0?

andy@7 ~/bin> python
Python 2.7.17 (default, Jul  1 2022, 15:56:32) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> name = input("Enter your name: ")
Enter your name: andrew
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 'andrew' is not defined

I got it figured out.

Use python3.10 python_test.py to run my script.

I also made a change in geany.

python3.10 “%f” as the execute command.(It was using the default older version of python.)