亲宝软件园·资讯

展开

python面向对象实现名片管理系统文件版

人气:0

import os
def print_menu():
 print("*"*50)
 print("  名片管理系统")
 print("  1.添加一个新名片")
 print("  2.删除一个名片信息")
 print("  3.修改一个名片信息")
 print("  4.查找一个名片信息")
 print("  5.显示添加过的名片信息")
 print("  6.保存添加的名片信息")
 print("  7.退出系统")
 print("*"*50)
card_infor = []
def add_new_card_infor():
 new_name = input("请输入要添加的名字:")
 new_qq = input("请输入Qq:")
 new_weixin = input("请输入微信号:")
 new_position = input("请输入工作职位")
 new_addr = input("请输入工作地址")
 """创建一个字典来存放添加的内容"""
 new_infor = {}
 new_infor['name'] = new_name
 new_infor['qq'] = new_qq
 new_infor['weixin'] = new_weixin
 new_infor['position'] = new_position
 new_infor['addr'] = new_addr
 """将字典刚入一个列表中"""
 global card_infor
 card_infor.append(new_infor)
def del_card_infor():
 del_name =input("请输入要删除的名片")

 global card_infor
 for temp in card_infor:
  if del_name == temp['name']:
   print("删除的名片如下")
   card_infor.remove(temp)
   print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
  else:
   print("不存在")
   return del_card_infor()
def change_care_infor():
 change_name_card = input("请输入需要修改的名片名字")
 global card_infor
 for temp in card_infor:
  if change_name_card == temp['name']:
   new_name = input("请输入要修改的名字")
   new_qq = input("请输入要修改的qq")
   new_weixin = input("请输入要修改的微信")
   new_position = input("请输入要修改的职业")
   new_addr = input("请输入要修改的地址")
   temp['name'] = new_name
   temp['qq'] = new_qq
   temp['weixin'] = new_weixin
   temp['position'] = new_position
   temp['addr'] = new_addr
   print("修改成功")
   break
  else:
   print("您要修改的名片不存在")

def find_card_infor():
 global card_infor
 find_name = input("请输入要在查找的内容\n")
 find = 0
 for temp in card_infor:
  if find_name == temp['name']:
   print("查询成功\n")
   print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
   find = 1
   break
  else:
   print("您要查询的名片不存在,请重新输入")
   return find_card_infor()
def display_card_infor():
 global card_infor
 print("姓名\t\tQQ\t\t微信\t\t工作\t\t住址")
 for temp in card_infor:
  print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(temp['name'],temp['qq'],temp['weixin'],temp['position'],temp['addr']))
def save_card_infor():
 global card_infor
 f = open("save_card.data","w")
 f.write(str(card_infor))
 f.close()
def load_card_infor():
 """恢复保存的信息"""
 global card_infor
 try:
  f = open('save_card.data')
  card_infor = eval(f.read())
  f.close()
 except Exception:
  pass
def main():
 load_card_infor()
 """把恢复保存的信息加载到程序中"""
 print_menu()
 """加载首页操作页面"""
 while True:
  num = int(input("请输入你要选择的功能序号"))
  if(num==1):
   add_new_card_infor()
  elif(num==2):
   del_card_infor()
  elif(num==3):
   change_care_infor()
  elif(num==4):
   find_card_infor()
  elif(num==5):
   display_card_infor()
  elif(num==6):
   save_card_infor()
  elif(num==7):
   break
  else:
   print("输入有误,请重新输入")
  print()
if __name__ == "__main__":
 main()

运行界面

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论