command - NameError when using input() with Python 3.4 -


i new python user , have been working through number of tutorials. has included running of code command prompt. worked fine when first tested code reason seems have stopped working , getting errors when using input(). have included code below , error message receiving.

code:

   import sys print (sys.version)  print("hello world") myname = input("what name?") print(myname)  if (myname == "matt"):     print("matt great!") elif (myname == "bob"):     print("bob ok") else:     print("hello world")  input("press enter 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 name?matt traceback (most recent call last):   file "c:\python34\scripts\projects\helloworld.py", line 6, in <module>     myname = input("what name?")   file "<string>", line 1, in <module> nameerror: name 'matt' not defined  c:\python34\scripts\projects> 

i know can occur when using older versions of python, have checked , sure using version 3.4 (checked using import sys etc.). have installed pycharm thing can think of has changed. code works in pycharm , idle not command prompt. appreciated.

from example , believe running script using - helloworld.py - cause windows lookup default application associated extension .py , run it.

i guessing in case when installed pycharm, somehow made python 2.7.7 default application .py files (or start) when directly run .py files (even command prompt) run using python 2.7.7 .

you said in comment when running python directly command prompt, getting python 3.4 , easiest way fix issue use run script.

run using command -

python helloworld.py 

as long term solution, may want consider changing default application associated .py files. can checkout this link guide on how that


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -