在这里我有我未完成的电话簿。我希望人们能够搜索,添加和删除字典中的人。我还没有添加删除功能,但是如何在通过关键字请求时允许此脚本重新开始。 (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”循环。 –