Python名片管理系统
找了很久的 bug,最后发现是 input 没转换类型……
1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 4 print(‘*‘*50) 5 print(‘名片管理系统‘) 6 print(‘*‘*50) 7 print(‘‘‘1. 新建名片 8 2. 删除名片 9 3. 修改名片 10 4. 查询名片 11 5. 显示所有名片 12 6. 退出管理系统 13 ‘‘‘) 14 List = [] 15 while True: 16 choice = int(input(‘请选择你的操作:‘))#记住要转换类型! 17 if choice == 1: 18 new_name = input(‘输入姓名:‘) 19 new_sex = input(‘输入性别:‘) 20 new_age = input(‘输入年龄:‘) 21 new_QQ = input(‘输入QQ号:‘) 22 card = {} 23 card[‘name‘] =new_name 24 card[‘sex‘] = new_sex 25 card[‘age‘] = new_age 26 card[‘QQ‘] = new_QQ 27 List.append(card) 28 print(List) 29 30 elif choice == 2: 31 fname = input(‘输入你要删除名片的姓名:‘) 32 fflag = 0#没找到 33 for temp in List: 34 if temp[‘name‘] == fname: 35 List.remove(temp)#此处宜用remove 36 print(List) 37 fflag = 1#找到了 38 break 39 if fflag == 0: 40 print(‘没有这张名片!‘) 41 42 elif choice == 3: 43 mname = input(‘输入要修改信息的名片的姓名:‘) 44 flag = 0 45 i = 0 46 for temp in List: 47 if mname == temp[‘name‘]: 48 flag = 1 49 print(‘%s\t%s\t%s\t%s‘%(temp[‘name‘], temp[‘sex‘], temp[‘age‘], temp[‘QQ‘])) 50 mchoice = int(input(‘选择要修改的信息:1. 姓名 2. 性别 3. 年龄 4. QQ 5. 退出 :‘))#记住转换类型!!! 51 while True: 52 if mchoice == 1: 53 temp[‘name‘] = input(‘输入修改后姓名:‘) 54 flag = 1 55 elif mchoice == 2: 56 temp[‘sex‘] = input(‘输入修改后性别:‘) 57 elif mchoice == 3: 58 temp[‘age‘] = input(‘输入修改后年龄:‘) 59 elif mchoice == 4: 60 temp[‘QQ‘] = input(‘输入修改后QQ:‘) 61 elif mchoice == 5: 62 break 63 else: 64 print(‘输入错误!‘) 65 print(‘姓名\t性别\t年龄\tQQ‘) 66 print(‘%s\t%s\t%s\t%s‘%(temp[‘name‘], temp[‘sex‘], temp[‘age‘], temp[‘QQ‘])) 67 break 68 if flag == 0: 69 print(‘无此名片!‘) 70 71 elif choice == 4: 72 fname = input(‘输入你要查询的名片中的姓名:‘) 73 fflag = 0#没找到 74 for temp in List: 75 if temp[‘name‘] == fname: 76 print(‘姓名\t性别\t年龄\tQQ‘) 77 print(‘%s\t%s\t%s\t%s‘%(temp[‘name‘], temp[‘sex‘], temp[‘age‘], temp[‘QQ‘])) 78 fflag = 1#找到了 79 break 80 if fflag == 0: 81 print(‘没有这张名片!‘) 82 elif choice == 5: 83 print(‘姓名\t性别\t年龄\tQQ‘) 84 for temp in List: 85 print(‘%s\t%s\t%s\t%s‘%(temp[‘name‘], temp[‘sex‘], temp[‘age‘], temp[‘QQ‘])) 86 elif choice == 6: 87 break 88 else: 89 print(‘操作错误!请重新选择!‘)
原文地址:https://www.cnblogs.com/lonelyWMW/p/9383928.html
时间: 2024-10-11 17:04:53