Python 知识要点:名片管理系统 1.0

# 1.程序启动,欢迎界面,显示功能菜单
print("*" * 30)
print("欢迎使用【名片管理系统1.0】")
print()
print("1.新建名片")
print("2.显示全部")
print("3.查询名片")
print()
print("0.退出系统")
print("*" * 30)

p_card = {"name": "",
          "telephone": "",
          "QQ": "",
          "mailbox": ""}
cards = []

# 2.根据选择,执行不同的功能
while True:
    # 3.用户根据数字选择不同的功能
    option = input("请输入您需使用的功能编号:")

    if int(option) == 1:
        # 4.名片记录用户【姓名,电话,QQ,邮箱】
        print("新建名片")

        p_card["name"] = input("姓名:")
        p_card["telephone"] = input("电话:")
        p_card["QQ"] = input("QQ:")
        p_card["mailbox"] = input("邮箱:")

        cards.append(p_card)
        print("添加成功!")

        print("*" * 30)

    elif int(option) == 2:
        print("显示全部名片")
        print(cards)

        print("*" * 30)

    elif int(option) == 3:
        # 5.查询到指定名片,可以选择修改或删除
        print("查询名片")

        p_name = input("请输入查询姓名:")
        for cards_dict in cards:
            if cards_dict["name"] == p_name:
                print("姓名: {}, 电话: {}, QQ: {}, 邮箱: {}".format(
                    cards_dict["name"], cards_dict["telephone"],
                    cards_dict["QQ"], cards_dict["mailbox"]))
                print("*" * 30)
option_2
= int(input("是否进行修改删除操作,是【1】,否【2】:")) print("*" * 30) if option_2 == 1: option_3 = int(input("请选择进行的操作,修改【1】,删除【2】:")) if option_3 == 1: cards_dict["name"] = input("请输入修改后姓名:") cards_dict["telephone"] = input("请输入修改后电话:") cards_dict["QQ"] = input("请输入修改后QQ:") cards_dict["mailbox"] = input("请输入修改后邮箱:") print("修改成功") elif option_3 == 2: cards.remove(cards_dict) print("删除成功") else: print("输入有误") else:
            break
       else: print("没有查询到【{}】的名片信息".format(p_name)) print("*" * 30) elif int(option) == 0: print("感谢您的使用!") print("*" * 30) break else: print("输入指令有误,请重新输入") print("*" * 30)

 

posted @ 2019-07-01 17:35  颗粒成仓  阅读(297)  评论(0编辑  收藏  举报