#定义功能界面函数
def info_print():
print('请选择')
print('1添加学员')
print('2删除学员')
print('3修改学员')
print('4查询学员')
print('5显示所有学员')
print('6退出系统')
#等待存储信息
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 = {}
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 serch_info():
serch_name = input('输入要查询的姓名')
global info
for i in info:
if serch_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']},{i['name']},{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:
serch_info()
elif user_num == 5:
print_all()
elif user_num == 6:
exit_flag = input('确定要退出吗?yes or no')
if exit_flag =='yes':
break
else:
print('输入有误')
02-09
605
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-19
692
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)