#学员信息在线管理系统
#定义一个用于存放学员信息的 列表 变量
stulist=[
{"name":"zhangsan","age":20,"classnum":"py1"},
{"name":"lisi","age":21,"classnum":"py2"},
{"name":"wangwu","age":22,"classnum":"py3"}]
#定义一个学生信息的输出函数
def showstu(stulist):
'''
学生信息的输出函数
'''
if len (stulist)==0:
print ("==================无学员信息!======================")
return
print ("|{0:<5} | {1:<10} | {2:<5} | {3:<10}|".format("sid","name","age","classnum"))
print ("-"*50)
for i in range(len(stulist)):
print ("|{0:<5} | {1:<10} | {2:<5} | {3:<10}|".format(i+1,stulist[i]["name"],stulist[i]["age"],stulist[i]["classnum"]))
while True:
print ("="*14,"学员信息在线管理系统","="*14)
print ("{0:1}{1:18}{2:18}".format(" ","1.查看学员信息","2.添加学员信息"))
print ("{0:1}{1:18}{2:18}".format(" ","3.删除学员信息","4.退出操作"))
print ("="*50)
key = input("请输入对应的选择:")
if key == "1":
print ("="*14,"学员信息查看","="*22)
showstu(stulist)
input("按回车键继续")
elif key == "2":
print ("="*14,"学员信息添加","="*22)
stu={}
stu["name"]=input("请输入要添加的学员姓名:")
stu["age"]=input("请输入要添加的学员年龄:")
stu["classnum"]=input("请输入要添加的学员班级:")
stulist.append(stu)
showstu(stulist)
input("按回车键继续")
elif key == "3":
print ("="*14,"学员信息删除","="*22)
sid = input("请输入要删除的学员信息id号")
del stulist[int(sid)-1]
showstu(stulist)
input("按回车键继续")
elif key == "4":
print ("==================== 再见! ======================")
break