python3名片管理系统控制台版

匿名 (未验证) 提交于 2019-12-02 22:11:45

系统主要是:1.新增名片 2.显示全部 3.查询名片 0.退出系统

card_main.py

 import card_tools  while True:     """         1.新增名片 2.显示全部 3.查询名片 0.退出系统     """      card_tools.show_menu()  # 显示系统菜单     action_str = card_tools.input_deal()      if action_str == 1:         print("您的操作是:%d" % action_str)         card_tools.new_card()         print()     elif action_str == 2:         print("您的操作是:%d" % action_str)         card_tools.show_all()         print()     elif action_str == 3:         print("您的操作是:%d" % action_str)         card_tools.find_card()         print()     elif action_str == 0:         print("退出系统")         break     else:         print("您输入的不正确") 

card_tools.py

 #! /usr/bin/python3 card_list = []   def input_deal():     """     输入处理     :return:     """     while True:         try:             action_str = int(input("请输入你的操作:"))         except ValueError:             print("输入不正确,请重新输入!")         else:             return action_str   def show_menu():     """     显示名片系统的菜单     :return:     """      print("*" * 50)     print("名片管理系统1.0".center(21, " "))     print("1.新建名片".center(10, "\t"))     print("2.显示全部".center(10, "\t"))     print("3.查询名片".center(10, "\t"))     print("0.退出系统".center(10, "\t"))     print("*" * 50)   def new_card():     """     新增名片     :return:     """      print("新增名片")     name = input("请输入您的名字:")     phone = input("请输入您的手机号码:")     qq = input("请输入您的QQ号码:")     email = input("请输入您的邮箱地址:")     card_dict = {"name": name, "phone": phone, "qq": qq, "email": email}     # print(card_dict)      card_list.append(card_dict);     print(card_list)   def show_all():     """     显示所有名片     :return:     """     for name in ["姓名", "电话", "QQ", "邮箱"]:         print(name, end="\t\t")     print()     # print(card_list)      if len(card_list) == 0:         print("名片为空,请添加。")      for card_dict in card_list:         print("%s\t\t\t%s\t\t\tt%s\t\t\t%s" % (             card_dict['name'], card_dict['phone'], card_dict['qq'], card_dict['email']))   def find_card():     """     查询名片     :return:     """     find_name = input("请输入您要查询的姓名:")     for card_dict in card_list:         if card_dict['name'] == find_name:             print("查询成功")             print(card_dict)             deal_card(card_dict)             break     else:         print("查询失败")   def deal_card(card_dict):     """     对名片进行修改,查询     :return:     """      action_str = input("请输入你要的操作:1.修改 2.删除 0.返回上级菜单")      if action_str == "1":         print("您的操作是:%s" % action_str)         name = deal_input(card_dict, input("请输入您的名字:"), "name")         phone = deal_input(card_dict, input("请输入您的手机号码:"), "phone")         qq = deal_input(card_dict, input("请输入您的QQ号码:"), "qq")         email = deal_input(card_dict, input("请输入您的邮箱地址:"), "email")         card_dict['name'] = name         card_dict['phone'] = phone         card_dict['qq'] = qq         card_dict['email'] = email      elif action_str == "2":         print("您的操作是:%s" % action_str)         card_list.remove(card_dict)         print("删除成功")     else:         print("返回上级菜单")   def deal_input(card_dict, str1, str2):     """     处理要修改的输入值     :param card_dict:     :param str1:     :param str2:     :return:     """     if len(str1) == 0:         return card_dict[str2]     else:         return str1 

文章来源: https://blog.csdn.net/u011842599/article/details/90676093
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!