def menu():
#首先定义功能列表函数menu()
print(" 名片管理系统 V1.0 ")
print("1:增加新用户")
print("2:删除新用户")
print("3:修改用户名")
print("4:查询用户名")
print("5:显示所有用户")
print("6:保存到文件")
print("7:退出本程序")
# 定义空列表存储用户信息
users = []
def add():
#定义追加新用户信息函数
new_info = {}
new_info['name'] = input("请输入你要增加的姓名:\n")
new_info['QQ'] = input("请输入你要增加的QQ:\n")
new_info["weixin"] = input("请输入你要增加的微信:\n")
new_info["address"] = input("请输入你要增加的住址:\n")
# 使用append方法追加字典元素到列表
users.append(new_info)
print("\n")
# users.append(name)
print(users)
#使用死循环 让程序不自动停止
def deluser():
name = input("请输入你要删除的姓名:\n")
count = 1
# if name in users.name:
for temp in users:
if temp['name'] == name:
count += 1
users.remove(temp)
print("删除后的列表为:%s" % users)
break
if (count == 1):
print("没有该用户")
def update():
count = 1
name = input("请输入你要更改的姓名:\n")
for temp in users:
if temp['name'] == name:
count += 1
after_name = input("请输入你更改后的名字\n")
after_qq = input("请输入你更改后的QQ\n")
after_weixin = input("请输入你更改后的名微信\n")
after_address = input("请输入你更改后的地址\n")
temp['name'] = after_name
temp['QQ'] = after_qq
temp['weixin'] = after_weixin
temp['address'] = after_address
print("更改后的列表为:%s" % users)
if count == 1:
print("没有该用户。")
def findName():
count = 1
find_name = input("请输入查询的名字")
for temp in users:
if temp['name'] == find_name:
count += 1
print("姓名:%s QQ:%s 微信:%s 住址:%s"%(temp['name'],temp['QQ'],temp['weixin'],temp['address']))
if count == 1:
print("么有该用户")
def show():
print("姓名\tQQ\t微信\t住址\t")
for temp in users:
print("%s\t %s\t%s\t %s" % (temp['name'], temp['QQ'], temp['weixin'], temp['address']))
def saveToFile():
f = open("userinfo.data","w")
f.write(str(users))
f.close()
def loadFile():
global users
try:
f = open("userinfo.data","r")
users = eval(f.read())
f.close()
except Exception:
pass def main():
loadFile()
menu()
while 1:
num = int(input("请输入操作序号:\n"))
if num == 1: # 追加新用户信息
add()
elif num == 2: # 删除指定指定用户信息
deluser()
elif num == 3: # 更改指定用户信息
update()
elif num == 4: #查询指定用户信息
findName()
elif num == 5: # 展示所有用户信息
show()
elif num ==6:
saveToFile()
elif num == 7:
break
if __name__ == "__main__":
main()

最新文章

  1. Linux基础介绍【第六篇】
  2. RecyclerView的坑
  3. <<Design Patterns>> Gang of Four
  4. HBase之表状态
  5. 超实用的JavaScript技巧及最佳实践
  6. BZOJ3928 [Cerc2014] Outer space invaders
  7. RM报表里的变量
  8. vector 与 set区别
  9. java精度计算代码,指定精确小数位
  10. 你不知道的document.write
  11. Docker镜像管理
  12. React路由 + 绝对路径引用
  13. iOS 正则表达式(二) RegexKitLite使用
  14. hdu2204 Eddy's爱好 打表+容斥原理
  15. Android逆向 APK文件组成
  16. React从0到1
  17. Hibernate入门第二课 Hibernate Tools for Eclipse Plugins安装
  18. 【BZOJ4140】共点圆加强版(二进制分组)
  19. .Net web 关于表单标题
  20. 解决日志unicode编码问题

热门文章

  1. 【NX二次开发】Block UI 整形
  2. [源码解析] 深度学习分布式训练框架 horovod (5) --- 融合框架
  3. 【题解】覆盖问题 BZOJ1052 HAOI2007 二分
  4. 【Javascript + Vue】实现随机生成迷宫图片
  5. MySQL explain type 连接类型
  6. rsync 基本使用
  7. 44、wget和curl的常用参数
  8. 34、mysql数据库(介绍)
  9. json串向后台传递数值自动四舍五入的问题
  10. AcWing 828. 模拟栈