![](/img/trans.png)
[英]Python how to input a list of 4 words and “fill in the blanks” to make a sentence
[英]how to input words to make a list of words in python?
这是我的代码:
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)
输出
当输入任何单词将其添加到列表中时,它会显示错误:
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
在 Python 2 中,您必须使用raw_input
。 input
评估给出的内容,因此评估错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.