1 #用来存储名片的列表 2 card_infors = [] 3 4 5 6 def print_menu(): 7 #1. 打印功能提示 8 print("="*50) 9 print(" 名片管理系统") 10 print("1. 增加一个新名片") 11 print("2. 删除一个名称") 12 print("3. 修改一个名片") 13 print("4. 查询一个名片") 14 print("5. 显示所有名片") 15 print("6. 退出系统") 16 print("="*50) 17 18 19 def add_new_card_infor(): 20 """完成文档输入:""" 21 new_name = input("请输入新的名字:") 22 new_qq = input("请输入新的QQ:") 23 new_weixin = input("请输入新的微信:") 24 new_addr = input("请输入地址:") 25 26 # 定义一个新的字典,用来存储新的名片 27 new_infor = {} 28 new_infor['name'] = new_name 29 new_infor['qq'] = new_qq 30 new_infor["weixin"] = new_weixin 31 new_infor['addr'] = new_addr 32 global card_infors 33 card_infors.append(new_infor) 34 35 36 def find_card_infor(): 37 find_name = input("请输入要查找的姓名:") 38 39 find_flag = 0 # 默认没有找到 40 41 global card_infors 42 for temp in card_infors: 43 if find_name == temp["name"]: 44 print("%s %s %s %s"%(temp['name'],temp['qq'],temp['weixin'],temp['addr'])) 45 find_flag=1 46 break 47 if find_flag == 0: 48 print("查无此人") 49 50 def show_all_infor(): 51 """显示所有信息""" 52 print("姓名 QQ 微信 住址") 53 global card_infors 54 for temp in card_infors: 55 # print(temp) 56 print("%s %s %s %s"%(temp['name'],temp['qq'],temp['weixin'],temp['addr'])) 57 58 59 def del_card_infor(): 60 del_name = input("请输入要查找的姓名:") 61 find_flag = 0 # 默认没找到 62 63 global card_infors 64 for temp in card_infors: 65 if del_name == temp["name"]: 66 card_infors.remove(temp) 67 find_flag = 1 68 show_all_infor() 69 break 70 if find_flag == 0: 71 print("查无此人") 72 73 74 def del_modify_infor(): 75 modify_name = input("请输入要修改信息的名称:") 76 find_flag = 0 77 78 global card_infors 79 for temp in card_infors: 80 if modify_name == temp["name"]: 81 modify_content = input("请输入要修改的信息,如name,qq,weixin,addr等:") 82 for name in temp.keys(): 83 print("+"*50) 84 print(temp.keys()) 85 print("+"*50) 86 print(name) 87 if modify_content == name: 88 modify_value = input("请输入要修改的值:") 89 temp[name] = modify_value 90 show_all_infor() 91 find_flag = 1 92 break 93 94 if find_flag == 0: 95 print("查无此人") 96 97 98 99 100 def main(): 101 """完成对整个程序得控制""" 102 103 print_menu() 104 while True: 105 #2. 获取用户的输入 106 num = int(input("请输入操作序号:")) 107 108 #3. 根据用户的数据执行相应的功能: 109 if num == 1: 110 add_new_card_infor() 111 elif num == 2: 112 del_card_infor() 113 elif num == 3: 114 del_modify_infor() 115 elif num == 4: 116 find_card_infor() 117 elif num == 5: 118 show_all_infor() 119 elif num == 6: 120 break 121 else: 122 print("输入有误,请重新输入:") 123 124 125 126 # 调用主函数 127 main()