1

my code was working find on Win machine , python 3.6 then i try the code on mac - terminal and its showing me error. Also have install latest version of python my code:

print ("==================================")
print ("    Print all String Character    ")
print ("==================================")

word_secund = input("Please add your word: ")
word_one = str(word_secund)

def list(text):
    word = 0
    for word in text:
        print(word)
print (list(word_one))

error message:

Please add your word: Slavo
Traceback (most recent call last):
  File "strings.py", line 5, in <module>
    word_secund = input("Please add your word: ")
  File "<string>", line 1, in <module>
NameError: name 'Slavo' is not defined
Derlin
  • 9,572
  • 2
  • 32
  • 53
Slavo7
  • 15
  • 1
  • 1
    try `raw_input` instead of `input` i suspect that although you have installed the latest version of python on your Mac you have two version of python installed on your machine and it is taken the python 2+ as default. – Aly Abdelaziz Apr 05 '17 at 22:05
  • 1
    I think you are right and I have conflict – Slavo7 Apr 06 '17 at 01:48

2 Answers2

1

This error happens with python2. Note that on Mac and Linux, the default python is python2. Try to run your program with the command

python3 yourfile.py

To avoid the error.

Derlin
  • 9,572
  • 2
  • 32
  • 53
1

check your python version "python --version" in command line. You might have more than 1 version installed and you might be using 2.x

Or try using raw_input instead of input. If that works, you're using 2.x

EDIT:

How can I remove the older version of Python because 100 % this is the problem

You might not want to remove the Python 2.7 which is by default used by your system. Check this answer: Remove all previous versions of python

How are you running your python program? If you are using a command line with the command "python name.py", you could just replace "python" with "python3" to run it with the python 3 interpreter. If you are using an IDE, they have an option to select the python interpreter, and you can select the 3.x there.

Community
  • 1
  • 1
Silencer310
  • 862
  • 2
  • 8
  • 25