dharmik abhangi
dharmik abhangi

Reputation: 1

how to input words to make a list of words in python?

It is my code:

input_string = input("enter any words to add it in list")
list = input_string.split(",")

for word in list:
    my_list = list.append(word)

print(my_list)

output

When enter any words to add it in listme,It will show the errors:

Traceback (most recent call last):

  File "<ipython-input-28-21d19c13b221>", line 1, in <module>
    runfile('D:/Python programme/test for list input.py', wdir='D:/Python programme')

  File "C:\Users\abhan\Anaconda2\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\abhan\Anaconda2\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 95, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "D:/Python programme/test for list input.py", line 2, in <module>
    input_string = input("enter any words to add it in list")

  File "C:\Users\abhan\Anaconda2\lib\site-packages\ipykernel\ipkernel.py", line 176, in <lambda>
    builtin_mod.input = lambda prompt='': eval(self.raw_input(prompt))

  File "<string>", line 1, in <module>

NameError: name 'me' is not defined

Upvotes: 0

Views: 43

Answers (1)

fractals
fractals

Reputation: 856

In Python 2, you have to use raw_input. input evaluates what was given, and hence the error message.

Upvotes: 1

Related Questions