import pickle
def title():#标签
print("-*-" * 50)
print(" " * 25, "广东财经大学员管理系统")
print(" " * 5, "1,添加学员信息")
print(" " * 5, "2,修改学员信息")
print(" " * 5, "3,删除学员")
print(" " * 5, "4,查询学员信息")
print(" " * 5, "5,成绩查询")
print(" " * 5, "6,添加成绩")
print(" " * 5, "7,退出")
print("-*-" * 50)
return int(input("请输入你要选择的操作序号:"))
def read():#从文件读出,程序前执行
pstudentnum_file = open(r"studentnum.pkl","rb") #设定一个接口mstudentnum_file,用读studentnum.pkl文件
studentnum = pickle.load(pstudentnum_file)
pstudentnum_file.close()
pdata_file = open(r"data.pkl","rb")
data = pickle.load(pdata_file)
pdata_file.close()
pgrade_file = open(r"grade.pkl","rb")
grade = pickle.load(pgrade_file)
pgrade_file.close()
return studentnum, data, grade
def write():#写入到文件,程序后执行
mstudentnum_file = open(r"studentnum.pkl","wb") #设定一个接口mstudentnum_file,用来写入东西到studentnum.pkl文件中
pickle.dump(studentnum,mstudentnum_file)
mstudentnum_file.close()
mdata_file = open(r"data.pkl","wb")
pickle.dump(data,mdata_file)
mdata_file.close()
mgrade_file = open(r"grade.pkl","wb")
pickle.dump(grade,mgrade_file)
mgrade_file.close()
def addstudent(studentnum,data,grade):#添加学员信息
print("-*-" * 50)
print(" " * 25, "添加")
print("请输入学员的信息(# 学号 姓名 性别 年龄 家庭住址):")
print("-*-" * 50)
while True:
list = [];
stu = input()
if stu not in studentnum:
studentnum.add(stu)
list.append(stu)
list.append(input())
list.append(input())
list.append(input())
list.append(input())
data[stu] = list
print("添加成功!")
else:
print("已经有该学员的信息,不能继续添加!")
s = input("按q退出,其它键继续:")
if s == "q":
break
def alter(studentnum,data,grade):#修改学员信息
print("-*-" * 50)
print(" "*25,"修改学员信息")
print("请输入学员的信息(# 学号 姓名 性别 年龄 家庭住址):")
print("-*-" * 50)
while True:
list = [];
stu = input()
if stu in studentnum:
list.append(stu)
list.append(input())
list.append(input())
list.append(input())
list.append(input())
data[stu] = list
print("修改成功!")
else:
print("没有这个学员!")
s = input("按q退出,其它键继续:")
if s == "q":
break
def delete(studentnum,data,grade):#删除学员信息
print("-*-" * 50)
print(" " * 25, "删除学员")
print("请输入学员的学号:")
while True:
stu = input()
if stu in studentnum:
data.pop(stu)
studentnum.remove(stu)
print("删除成功!")
else:
print("没有这个学员!")
s = input("按q退出,其它键继续:")
if s == "q":
break
def query(studentnum,data,grade):#查询学员信息
print("-*-" * 50)
print(" " * 25, "查询学员信息")
print("请输入学员的学号:")
while True:
stu = input()
if stu in studentnum:
print(data[stu])
else:
print("没有这个学员!")
s = input("按q退出,其它键继续:")
if s == "q":
break
def grade_query(studentnum,data,grade):#成绩查询
print("-*-" * 50)
print(" " * 25, "成绩查询")
print("请输入学员的学号:")
while True:
stu = input()
if stu in studentnum:
if stu in grade:
print(grade[stu])
else:
print("该学员没有成绩信息")
else:
print("没有这个学员")
s = input("按q退出,其它键继续:")
if s == "q":
break
def grade_add(studentnum,data,grade):#添加成绩
print("-*-" * 50)
print(" " * 25, "添加成绩")
while True:
print("请输入学员的学号:")
stu = input()
if stu in studentnum:
print("请输入添加的成绩:")
stu1 = input()
grade[stu].append(stu1)
print("添加成功!")
else:
print("没有这个学员")
s = input("按q退出,其它键继续:")
if s == "q":
break
studentnum, data, grade = read() #从文件读出,程序前执行
while True:
str = title()
if str == 1:
addstudent(studentnum,data,grade)#添加学员信息
if str == 2:
alter(studentnum,data,grade) #修改学员信息
if str == 3:
delete(studentnum,data,grade) #删除学员
if str == 4:
query(studentnum, data, grade) #查询学员信息
if str == 5:
grade_query(studentnum, data, grade) #成绩查询
if str == 6:
grade_add(studentnum, data, grade) #添加成绩
if str == 7: #退出
break;
write() #写入到文件,程序后执行