22-名片管理系统

cards_main.py

 1 #!/usr/bin/env python3
 2 # coding=utf-8
 3 import cards_tools
 4 
 5 
 6 def main():
 7     while True:
 8         cards_tools.show_menu()
 9 
10         action = input("请选择操作功能:")
11         print("您选择的操作是:%s" % action)
12 
13         if action in ['1', '2', '3']:
14             if action == '1':
15                 cards_tools.new_card()
16             elif action == '2':
17                 cards_tools.show_all()
18             elif action == '3':
19                 cards_tools.search_card()
20         elif action == '0':
21             print('欢迎再次使用【名片管理系统】')
22             break
23         else:
24             print('输入错误,请重新输入')
25 
26 
27 if __name__ == '__main__':
28     main()

cards_input.py

1 # coding=utf-8
2 
3 
4 def input_card_info(dict_value, tip_mess):
5     result = input(tip_mess)
6     if len(result) > 0:
7         return result
8     else:
9         return dict_value

cards_tools.py

  1 # coding=utf-8
  2 
  3 import cards_input
  4 
  5 card_list = []
  6 
  7 
  8 def show_menu():
  9     """显示菜单
 10     """
 11     print("*" * 50)
 12     print("欢迎使用【菜单管理系统】V1.0")
 13     print("")
 14     print("1. 新建名片")
 15     print("2. 显示全部")
 16     print("3. 查询名片")
 17     print("")
 18     print("0. 退出系统")
 19     print("*" * 50)
 20 
 21 
 22 def new_card():
 23     """新建名片
 24     """
 25     print("-" * 50)
 26     print("功能:新建名片")
 27 
 28     name = input('请输入姓名:')
 29     phone = input('请输入电话:')
 30     qq = input('请输入QQ号码:')
 31     email = input('请输入邮箱:')
 32 
 33     card_dict = {
 34         'name': name,
 35         'phone': phone,
 36         'qq': qq,
 37         'email': email
 38     }
 39 
 40     card_list.append(card_dict)
 41 
 42     # print(card_list)
 43 
 44     print('成功添加 %s 的名片' % card_dict['name'])
 45 
 46 
 47 def show_all():
 48     """显示全部
 49     """
 50     print("-" * 50)
 51     print("功能:显示全部")
 52 
 53     if len(card_list) == 0:
 54         print("提示:没有任何名片记录")
 55         return
 56 
 57     for name in ['姓名', '电话', 'QQ', '邮箱']:
 58         print(name, end='\t\t')
 59 
 60     print('')
 61     print('=' * 50)
 62 
 63     for card_dict in card_list:
 64         print('%s\t\t%s\t\t%s\t\t%s' % (card_dict['name'],
 65                                         card_dict['phone'],
 66                                         card_dict['qq'],
 67                                         card_dict['email']))
 68 
 69 
 70 def search_card():
 71     """搜索名片
 72     """
 73     print("-" * 50)
 74     print("功能:搜索名片")
 75 
 76     find_name = input('请输入要搜索的姓名:')
 77 
 78     for card_dict in card_list:
 79         if card_dict['name'] == find_name:
 80             print('姓名\t\t电话\t\tQQ\t\t邮箱')
 81             print('-' * 50)
 82 
 83             print("%s\t\t%s\t\t%s\t\t%s" % (
 84                 card_dict["name"],
 85                 card_dict["phone"],
 86                 card_dict["qq"],
 87                 card_dict["email"]))
 88 
 89             print("-" * 50)
 90 
 91             deal_card(card_dict)
 92 
 93             break
 94         else:
 95             print('没有找到 %s' % find_name)
 96 
 97 
 98 def deal_card(card_dict):
 99     action = input('请输入对名片的操作:(1)修改(2)删除(0)返回上级菜单')
100     if action == '1':
101         card_dict['name'] = cards_input.input_card_info(card_dict['name'], '请输入姓名[回车不修改]:')
102         card_dict['phone'] = cards_input.input_card_info(card_dict['phone'], '请输入电话[回车不修改]:')
103         card_dict['qq'] = cards_input.input_card_info(card_dict['qq'], '请输入QQ[回车不修改]:')
104         card_dict['email'] = cards_input.input_card_info(card_dict['email'], '请输入邮箱[回车不修改]:')
105 
106         print('%s 的名片修改成功' % card_dict['name'])
107     elif action == '2':
108         card_list.remove(card_dict)
109         print('删除名片成功')

 

posted on 2019-03-05 20:17  hbzxpost  阅读(165)  评论(0编辑  收藏  举报