代码如下:
def info_print():
print("请选择功能----------------")
print("1,添加成员")
print("2,删除成员")
print("3,修改成员")
print("4,查询成员")
print("5,显示所有成员")
print("6,退出系统")
print("-" * 24)
info = []
def add_info():
"""添加学员信息"""
new_id = input('请输入学号:')
new_name = input('请输入姓名:')
new_tel = input('请输入手机号:')
global info
for i in info:
if new_name == i['name']:
print('该用户已经存在!')
return
info_dict = dict()
info_dict['id'] = new_id
info_dict['name'] = new_name
info_dict['tel'] = new_tel
info.append(info_dict)
print(info)
def del_info():
"""删除学员"""
del_name = input('请输入要删除的学员的姓名:')
global info
for i in info:
if del_name == i['name']:
info.remove(i)
break
else:
print('该学员不存在')
print(info)
def modify_info():
"""修改函数"""
modify_name = input('请输入要修改的学员的姓名:')
global info
for i in info:
if modify_name == i['name']:
i['tel'] = input('请输入新的手机号:')
break
else:
print('该学员不存在')
print(info)
def search_info():
"""查询学员"""
search_name = input('请输入要查找的学员姓名:')
global info
for i in info:
if search_name == i['name']:
print('查找到的学员信息如下:-----------')
print(f"该学员的学号是{i['id']}, 姓名是{i['name']}, 手机号是{i['tel']}")
break
else:
print('该学员不存在')
def print_all():
"""显示所有学员的信息"""
print('学号\t姓名\t手机号')
for i in info:
print(f"{i['id']}\t{i['name']}\t{i['tel']}")
while True:
info_print()
user_num = int(input('请输入功能序号:'))
if user_num == 1:
add_info()
elif user_num == 2:
del_info()
elif user_num == 3:
modify_info()
elif user_num == 4:
search_info()
elif user_num == 5:
print_all()
elif user_num == 6:
exit_flag = input('确定要退出吗?yes or no')
if exit_flag == 'yes':
break
else:
print('输入的功能序号有误')
|