I am a new Python user and I have been working through a number of tutorials. This has included running some of the code from the Command Prompt. This worked fine when I first tested the code but for some reason it seems to have stopped working and I am now getting errors when using Input(). I have included the code below and the error message I am receiving.
Code:
import sys
print (sys.version)
print("hello world")
myName = input("What is your name?")
print(myName)
if (myName == "Matt"):
print("Matt is great!")
elif (myName == "Bob"):
print("Bob is ok")
else:
print("Hello world")
input("Press enter to continue")
Error Message:
C:\Users\matt.xxxx>cd C:\Python34\Scripts\Projects
C:\Python34\Scripts\Projects>helloworld.py
2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)]
hello world
What is your name?Matt
Traceback (most recent call last):
File "C:\Python34\Scripts\Projects\helloworld.py", line 6, in <module>
myName = input("What is your name?")
File "<string>", line 1, in <module>
NameError: name 'Matt' is not defined
C:\Python34\Scripts\Projects>
I know this can occur when using older versions of python, however I have checked and I am fairly sure I am using version 3.4 (checked using import sys etc.). I have recently installed PyCharm which is the only thing I can think of that has changed. The code works in PyCharm and from IDLE but not from the Command Prompt. Any help would be much appreciated.
import sys; print(sys.version)inside your script?echo %PATH%in your command prompt