名片管理系统python版

作者:WangF0 时间:2021-08-06 01:50:15 

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


import os
list_all = []

def page():
"""输出主页面"""
print("*" * 30)
print("欢迎使用[名片管理系统]v2.0")
print()
print("1.新建名片")
print("2.查看全部")
print("3.查询名片")
print("4.保存信息")
print()
print("0.退出系统")
print("=" * 30)

def new_cards():
"""接收用户输入的信息保存至字典"""
dict_1 = {"name": input("姓名:"),
 "age": input("年龄:"),
 "phone": input("电话:"),
 "email": input("邮箱:")}
# 将字典添加至列表
list_all.append(dict_1)

def check_all():
"""将所有的字典信息进行打印"""
if len(list_all) > 0:
print("姓名\t\t年龄\t\t电话\t\t邮箱")
for i in list_all:
 print("%s\t\t%s\t\t%s\t\t%s" % (i["name"], i["age"],
     i["phone"], i["email"]))
else:
 print("还没有任何信息")

def check_cards():
"""查询名片"""
user = input("请输入要查询的姓名:")
for i in list_all: # 遍历全局列表,将存入的字典依次取出
if i['name'] == user: # 如果字典的值跟用户搜索的值相同打印字典
 print("姓名\t\t年龄\t\t电话\t\t邮箱")
 print("%s\t\t%s\t\t%s\t\t%s" % (i["name"], i["age"],
     i["phone"], i["email"]))
 revise_cards(i)
else:
 print("没有查询到您搜索的信息")

def revise_cards(dict_1):
"""修改名片,接收之前已经查到的字典"""
while True:
user_choor = input("1.修改名片 2.删除名片 0.返回主菜单")
if user_choor == "1": # 如果用户输入1执行修改功能
 print("修改名片,注:修改直接输入修改内容,回车不修改")
 dict_1["name"] = revise(dict_1["name"], input("姓名"))
 dict_1["age"] = revise(dict_1["age"], input("年龄"))
 dict_1["phone"] = revise(dict_1["phone"], input("电话"))
 dict_1["email"] = revise(dict_1["email"], input("邮箱"))
 print("修改成功")
 break
# laturn
elif user_choor == "2": # 如果输入2删除字典
 list_all.remove(dict_1)
 print("删除名片成功")
 break
elif user_choor == "0":
 break
else:
 print("输入错误请重新输入")

def revise(old, new):
"""实现回车不修改的功能"""
if len(new) <= 0:

return old
else:
return new

def save_dir():
"""将文件保存至指定文件"""
a = open("123.xlsx", "w")
a.write(str(list_all))
a.close()
print("保存成功")

def read_dir():
"""读取文件"""
if os.path.exists("123.data"):
a = open("123.data", "r")
b = eval(a.read())
global list_all
list_all = b
a.close()
import cards_tools
# 读取文件
cards_tools.read_dir()
while True:
cards_tools.page()
user_input = input("请选择您要执行的操作")
if user_input == "1":
print("即将执行:新建名片")
cards_tools.new_cards()
elif user_input == "2":
print("即将执行:查看全部")
cards_tools.check_all()
elif user_input == "3":
print("即将执行:查询名片")
cards_tools.check_cards()
elif user_input == "4":
print("即将执行:保存信息")
cards_tools.save_dir()
elif user_input == "0":
print("欢迎下次使用[名片管理系统]")
exit()
else:
print("你的输入有误,请重新输入")

更多学习资料请关注专题《管理系统开发》。

来源:http://blog.csdn.net/wf134/article/details/78409464

标签:python,管理系统
0
投稿

猜你喜欢

  • 如何在python中使用selenium的示例

    2023-07-15 20:52:09
  • 致Python初学者 Anaconda入门使用指南完整版

    2021-09-08 04:48:36
  • escape,encodeURI,encodeURIComponent函数比较

    2008-01-27 11:19:00
  • 记一次成功的sql注入入侵检测附带sql性能优化

    2011-09-30 11:29:39
  • 如何理解PHP程序执行的过程原理

    2023-10-08 14:45:10
  • Django使用Celery加redis执行异步任务的实例内容

    2022-08-25 18:09:53
  • 新年快乐! python实现绚烂的烟花绽放效果

    2022-01-15 13:18:00
  • Oracle常见错误代码的分析与解决

    2010-07-26 13:01:00
  • python opencv进行图像拼接

    2022-09-10 16:13:01
  • Python3中的bytes类型和str类型

    2022-06-23 08:14:29
  • python广度优先搜索得到两点间最短路径

    2023-09-05 02:06:24
  • 一文详解Python灰色预测模型实现示例

    2023-05-11 01:45:21
  • Python中pyecharts安装及安装失败的解决方法

    2021-01-13 06:00:52
  • Django的ListView超详细用法(含分页paginate)

    2021-02-13 00:53:41
  • python基于property()函数定义属性

    2022-11-01 04:55:14
  • MySQL 视图,第1349号错误

    2008-05-18 13:04:00
  • python字典与json转换的方法总结

    2022-10-20 07:58:56
  • python基于exchange函数发送邮件过程详解

    2021-03-23 02:12:22
  • matlab中imadjust函数的作用及应用举例

    2021-09-12 21:34:06
  • python类的继承实例详解

    2021-04-10 07:22:33
  • asp之家 网络编程 m.aspxhome.com