在這裏我有我未完成的電話簿。我希望人們能夠搜索,添加和刪除字典中的人。我還沒有添加刪除功能,但是如何在通過關鍵字請求時允許此腳本重新開始。 (EG。你想執行另一個功能嗎?[是/否])如何循環這本詞典?
那麼,我將如何使每個函數(或者語句)返回到開始?
details = {"Toby": "123", "James": "234", "Paul": "345"}
print("Welcome To The Telephone Directory.\n")
print("To search out specific details, please type Search.\n To add a new person to the Directory, type Add.\n To change someone's details, please type Edit.")
inputKey = input();
if(input() == inputKey.strip() in "search Search SEARCH".split()):
print("Please enter the name of the customer.")
customer = input()
print("Number:" ,details.get(customer))
if(customer not in details):
print("I'm sorry, but the person you defined is not in the directory.")
elif(input() == inputKey.strip() in "add Add ADD AdD aDD".split()):
print("Please enter the full name of the person you would like to add to the directory.")
addedcustomer = input()
print("Now, please enter their number.")
addednumber = int(input())
details.add [addedcustomer : addednumber]
print(details)
我想你回答了你自己的問題,當你標記這與'loops' – Harrison
使用while循環,而由用戶選擇的選項不是「N」循環。 –