2014-03-18 66 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在這種情況下,請點擊投票計數下方的勾號以接受答案,以便它變成綠色。它向其他用戶表明您的問題已解決,併爲我提供幫助而獲得信任。 –