所以这是我的问题。我正在 python 3.3.2 中创建电话目录,我需要知道如何调用单独的函数。这是我的代码:
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.")
search = input();
if(input() == search.strip() in "search Search SEARCH".split()):
def search():
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.")
flag = True
while flag:
search()
flag = input("Would you like to look up another person? [Y/N]") == "y"
if(input() == add.strip() in "add Add ADD".split()):
def add():
print("Please enter the name of the new entry.")
name = input()
print("Now enter the entry's phone number.")
telNumber = input()
details[name] = telNumber
print("You have succesfully added a new entry:\n",name,"\n",telNumber)
所以我需要知道如何从一开始就调用 Add 函数。
有任何想法吗?