通讯录模拟小试

通讯录模拟

def ad():
    name = input("姓名:")
    iphone = input("联系电话:")
    mp_dict = {
     }
    mp_dict["name"] = name
    mp_dict["iphone"] = iphone
    mp_list.append(mp_dict)
    print("添加成功:\nname:%s\niphone:%s" % (name,  iphone))
def de():
    name = input("请输入要删除的姓名:")
    j = 0
    for temp in mp_list:
        if name == temp["name"]:
            del mp_list[j]
            print("删除成功")
            break
        else:
            j += 1
            continue
            print("无此人信息")
def re():
    new_name = input("请输入要修改的姓名:")
    for temp in mp_list:
        if new_name == temp["name"]:
            print("已找到此人信息,请进行操作:")
            new_name = input("请输入修改后的姓名:")
            new_iphone = input("请输入修改后的iphone:")
            temp["name"] = new_name3
            temp["iphone"] = new_iphone
            print(mp_list)
            break
    else:
        print("无此人信息")
def qu():
    find_name = input("请输入要查询的姓名:")
    for temp in mp_list:
        if find_name == temp["name"]:
            print("已找到", 'name:', temp['name'],  'iphone:', temp['iphone']
              )
            break
    else:
        print("无此人信息")
  • main

def main():
    print("*"*30)
    print("通讯录模拟")
    print("1.添加\n"
          "2.删除\n"
          "3.修改\n"
          "4.查询\n"
          "5.退出")
    print("*"*30)
    while True:
        try:
            i = input("请输入选项:")
            i = int(i)
            if i == 1:
                ad()
            elif i == 2:
                de()
            elif i == 3:
                re()
            elif i == 4:
                qu()
            elif i == 5:
                print("结束运行")
                break
        except:
            print("异常输入")

运行效果
******************************
通讯录模拟
1.添加
2.删除
3.修改
4.查询
5.退出
******************************

你可能感兴趣的:(Python数据分析,通讯录模拟)