我正在嘗試創建一個程序,用於詢問用戶是否想向列表中添加名稱,從列表中刪除名稱或顯示列表中的名稱。我收到了一點點的問題,我有一個問題在請求完成後重新出現問題。所以在「1」被按下並且動作完成之後,我想再次出現問題直到用戶退出程序。Python名稱項目
這裏是我
#Creating a Searching?
names = []
answer = input("Create An Entry [Press 1] \nDisplay List [Press 2] \nEdit an Entry [Press 3] \nRemove Entry [Press 4] \nQuit [Press 5]")
# IF creating
if answer == "1" :
# collect information
firstname = input("What is the persons first name? ")
#add data
names.append(firstname)
answer = input("Create An Entry [Press 1] \nDisplay List [Press 2] \nEdit an Entry [Press 3] \nRemove Entry [Press 4] \nQuit [Press 5]")
# Display Data
elif answer == "2" :
print(names)
answer = input("Create An Entry [Press 1] \nDisplay List [Press 2] \nEdit an Entry [Press 3] \nRemove Entry [Press 4] \nQuit [Press 5]")
# USER Quit
elif answer == "5":
exit()
爲什麼不使用while循環? – 2013-04-25 20:12:33
@Bartlomiej Lewandowski我真的很新的蟒蛇我怎麼會這樣做 – zachstarnes 2013-04-25 20:13:56
http://docs.python.org/2/reference/compound_stmts.html#while – cmd 2013-04-25 20:15:30