Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 函数,用于将用户输入存储在列表、元组或字典中_Python_List_Loops_For Loop_Input - Fatal编程技术网

Python 函数,用于将用户输入存储在列表、元组或字典中

Python 函数,用于将用户输入存储在列表、元组或字典中,python,list,loops,for-loop,input,Python,List,Loops,For Loop,Input,我想让这段代码在运行时为用户输入工作,以便用户输入可以存储在word中,并可以在运行时for循环中使用 应该如何做?list=[None]*3 words = input("Enter a word to find its length: ") for x in words: print x, len(x) x=真 z=0 z

我想让这段代码在运行时为用户输入工作,以便用户输入可以存储在word中,并可以在运行时for循环中使用

应该如何做?

list=[None]*3
words = input("Enter a word to find its length: ")

for x in words:
    print x, len(x)
x=真 z=0 z<3时: y=原始输入(“输入一个单词以查找其长度:”) 如果(y==“n”): x=假; 其他: 列表[z]=y; 打印长度(列表[z]); z+=1
这有点像蟒蛇:

list = [None]*3
x = True

z = 0
while z < 3:
    y = raw_input("Enter a word to find its length: ")
    if(y == "n"):
        x = False;
    else:
        list[z] = y;
        print len(list[z]);
        z +=1 

它不是按原样工作吗?我相信他希望用户能够输入多个单词list=[None]*3x=True z=0,而z<3:y=raw_输入(“输入一个单词以查找其长度:”)if(y==“n”):x=False;其他:列表[z]=y;打印长度(列表[z]);z+=1//这是我发现自己的答案,这次它起作用了
result = [None] * 3
for index in range(len(result)):
    y = raw_input("Enter a word to find its length: ")
    if y == "n":
        break
    else:
        result[index] = y
        print len(result[index])