python简易学员管理系统
def info_print():
print("请选择功能------------")
print("1. 添加学员")
print("2. 删除学员")
print("3. 修改学员")
print("4. 查询学员")
print("5. 显示所有学员")
print("-"*20)
info = []
def add_info():
"""
添加学员函数
如果学员信息存在 报错 不存在添加数据
:return:
"""
new_id = input("请输入学号:")
new_name = input("请输入姓名:")
new_tel = input("请输入手机号:")
global info
for i in info:
if new_name == i['name']:
print("此用户已经存在")
return
info_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():
"""
删除学员
:return:
"""
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():
"""
修改函数
:return:
"""
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():
"""
查询学员
:return:
"""
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():
"""
显示所有学员的信息
:return:
"""
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('确定要退出系统吗?yea or no')
if exit_flag == 'yes':
break
else:
print("输入有误")