![](/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.