import tools
while True:
tools.show_menu()
msg = input(“请输入需要的操作:”)
if msg == “0”:
break
if msg == “1”:
tools.add_card()
elif msg == “2”:
tools.read_cards()
elif msg == “3”:
tools.search_card()
import tools
while True:
tools.show_menu()
msg = input(“请输入需要的操作:”)
if msg == “0”:
break
if msg == “1”:
tools.add_card()
elif msg == “2”:
tools.read_cards()
elif msg == “3”:
tools.search_card()
user_list = [
{“name”: “张三”, “tel”: 123123, “qq”: 789789, “email”: "123@qq.com"},
{“name”: “王五”, “tel”: 123123, “qq”: 789789, “email”: "123@qq.com"},
{“name”: “赵六”, “tel”: 123123, “qq”: 789789, “email”: "123@qq.com"},
{“name”: “田七”, “tel”: 123123, “qq”: 789789, “email”: "123@qq.com"},
{“name”: “李四”, “tel”: 123123, “qq”: 789789, “email”: "123@qq.com"}
] # 存储数据的容器(暂时代替数据库)
def show_menu():
“”“欢迎界面,菜单栏”""
print("" * 60, end="")
print()
print(“欢迎使用【名片管理系统】V1.0”)
print()
print(“1. 新建名片”)
print(“2. 显示全部”)
print(“3. 查询名片”)
print()
print(“0. 退出系统”)
print("" * 60, end="")
print()
def add_card():
“”“新建名片”""
print(“新建名片”)
name = input(“姓名:”)
tel = input(“电话:”)
QQ = input(“QQ:”)
email = input(“邮箱:”)
print(‘用户姓名%s,电话%s,扣扣%s,邮箱%s’ % (name, tel, QQ, email))
# 第一步,完成用户数据字典的一个生成,定义一个字典
user_dict = {
“name”: name,
“tel”: tel,
“qq”: QQ,
“email”: email
}
print(‘构建好的字典’, user_dict)
user_list.append(user_dict)
def read_cards():
“”“查看名片”""
print(“姓名\t\t电话\t\tQQ\t\t\t邮箱”)
for d in user_list:
print("%s\t\t%s\t\t%s\t\t%s" % (d[‘name’], d[‘tel’], d[‘qq’], d[‘email’]))
def search_card():
“”“搜索名片”""
search_name = input(‘请输入你要搜索的名字:’)
for d in user_list:
# print(‘字典’, d)
if d[‘name’] == search_name: # 验证是否查找成功
print(“姓名\t\t电话\t\tQQ\t\t\t邮箱”)
print("%s\t\t%s\t\t%s\t\t%s" % (d[‘name’], d[‘tel’], d[‘qq’], d[‘email’]))
##############修改数据
# 定义一个操作id
act_id = input(“请输入需要的操作:1-编辑;2-删除;0-返回上一级:”)
if act_id == “1”:
print(‘编辑字典’)
# 弹出输入框,提示我们输入对应的新数据,输入完毕,会修改数据
new_name = input(‘新的姓名:’)
new_tel = input(‘新的电话:’)
new_qq = input(‘新的QQ:’)
new_email = input(‘新的邮箱:’)
# 字典[键] = 新的值
# 处理,如果用户输入的是回车,那么不修改原来的数据(保留原来的数据)
d['tel'] = new_tel
d['name'] = new_name
d['qq'] = new_qq
d['email'] = new_email
print(d)
elif act_id == "2":
print('删除字典')
user_list.remove(d)
break # break要写在当前这个小分支的最后一行,因为在break后面的代码不会被执行
else:
print('你搜索的用户%s没有找到' % search_name)