0Bennyman 0Bennyman - 9 months ago 19
Python Question

Python code not working in CMD but works in IDLE?

I'm new to Python and have been trying to make a small test game but when I run my program in CMD it gives of this error.

What Is Your Name?
Traceback (most recent call last):
File "C:\Users\User\Documents\Python Games\Test.py", line 2, in <module>
myName = input()
File "<string>", line 1, in <module>
NameError: name 'Test' is not defined

Though this works fine in IDLE. This is the top of the code.

print('What Is Your Name?')
myName = input()
print('Hello '+str(myName)+' It is good to meet you!')


Its because of python version change. You probably have two pythons installed. Python2.x is in the PATH. And you have the Python 3.x IDLE.

NameError: name 'Test' is not defined is because its python 2.x

Change myName = input() to myName = raw_input().

And it would work in python 2.x

Your IDLE version must be python 3.x where there is no raw_input().