python3实现名片管理系统

Python itxz 2个月前 (11-30) 18次浏览 0个评论

本文实例为大家分享了python3实现名片管理系统的具体代码,供大家参考,具体内容如下

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

python3实现名片管理系统

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("您输入的不正确")
#! /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

IT学者 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python3实现名片管理系统
喜欢 (0)

您必须 登录 才能发表评论!