2014-03-18 70 views
-1

社区,如何将用户输入存储在while循环中? (python)

我是一个关于python的总noob,我想用程序创建一个名称统计。 我的代码(我使用Python 3.4.0):

while True: 
    eingabe = input ('Please enter a name: ') 
    print (eingabe) 
    if eingabe == '': 
     break 

所以现在我想用户输入存储在列表中。我怎样才能做到这一点?

亲切的问候, 丽莎

+0

http://docs.python.org/2/tutorial/datastructures.html – smassey

+0

http://stackoverflow.com/questions/8114355/loop-until-a-specific-user-input – adam

回答

1

只要定义一个list,然后新的价值观将其与.append()补充。

names = [] # Here we define an empty list. 
while True: 
    eingabe = input('Please enter a name: ') 
    if not eingabe: 
     break 

    names.append(eingabe) 
    print(eingabe) 
+0

谢谢非常!我不确定把附加部分放在哪里! – user3429227

+0

@ user3429227在这种情况下,请点击投票计数下方的勾号以接受答案,以便它变成绿色。它向其他用户表明您的问题已解决,并为我提供帮助而获得信任。 –