# 学生信息管理系统
已实现功能:添加学生信息并自动生成学号,按学号或姓名查看学生信息,删除学生信息,查看所有学生信息,查看指定学生平均成绩.
未实现功能:登录系统,数据本地化.
#已经存好的5个学生信息的字典
dict1 = {'name':'a','stu_num':'py001','English':90,'P.E':90,'Art':90,'Math':90,'age':18}
dict2 = {'name':'b','stu_num':'py002','English':80,'P.E':80,'Art':95,'Math':80,'age':19}
dict3 = {'name':'c','stu_num':'py003','English':99,'P.E':99,'Art':99,'Math':99,'age':20}
dict4 = {'name':'d','stu_num':'py004','English':60,'P.E':90,'Art':90,'Math':60,'age':17}
dict5 = {'name':'e','stu_num':'py005','English':90,'P.E':60,'Art':90,'Math':90,'age':18}
Py1807 =[dict1,dict2,dict3,dict4,dict5]
#声明添加学生信息函数
def add_stu():
print('+++++++您选择了添加新学生信息++++++++')
name = input('!!!请输入学生姓名!!!:')
English = input('!!!请输入英语成绩!!!:')
P_E = input('!!!请输入体育成绩!!!:')
Art = input('!!!请输入美术成绩!!!:')
Math = input('!!!请输入数学成绩!!!:')
age = input('!!!请输入年龄!!!:')
stu_num = 'py00'+str(len(Py1807)+1) #自动生成学号
new_dict = {'name':name,'stu_num':stu_num,'English':English,'P.E':P_E,'Art':Art,'Math':Math,'age':age} #新字典
Py1807.append(new_dict) #将新字典存入列表
print("+++++++++++++++添加成功!+++++++++++++++")
print('++++++++输入1继续添加学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
add_stu()
else:
pass
#声明查看指定学生信息函数
def find_stu():
# 声明按姓名查找学生信息函数
def find_stu1():
print('+++您选择了按姓名查询指定学生信息++++')
none = 0 # 用来计数循环了多少次才到需要的信息
stu_name = input('请输入学生姓名:')
for index1 in range(0, len(Py1807)):
if stu_name == Py1807[index1]['name']:
none += 1
print(Py1807[index1])
continue
print('++++++++输入1继续查看学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_stu()
else:
break
if none == 0: # 如果没有找到信息
print('++++++++++++不存在该学生!++++++++++++')
print('++++++++输入1继续查看学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_stu()
else:
pass
# 声明按学号查找学生信息函数
def find_stu2():
print('++++++您选择了查询指定学生信息+++++++')
none = 0 # 用来计数循环了多少次才到需要的信息
stu_num = input('请输入学生姓名:')
for index1 in range(0, len(Py1807)):
if stu_num == Py1807[index1]['stu_num']:
none += 1
print(Py1807[index1])
print('++++++++输入1继续查看学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_stu()
else:
break
if none == 0: # 如果没有找到信息
print('++++++++++++不存在该学生!++++++++++++')
print('++++++++输入1继续查看学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_stu()
else:
pass
#选择按姓名or学号查看学生信息
print('++++++++输入1按姓名查看学生信息++++++++')
print('++++++++输入2按学号查看学生信息++++++++')
instruct3 = str(input('!!!请输入指令!!!'))
if instruct3 == str(1):
find_stu1()
elif instruct3 == str(2):
find_stu2()
else:
print('无效的指令')
# 声明删除指定学生信息函数
def del_stu():
none = 0
print('++++++您选择了删除指定学生信息+++++++')
del_name = str(input('请输入需要删除学生姓名:'))
for student in Py1807[:]:
if del_name == str(student['name']) :
none += 1
Py1807.remove(student)
print('+++++++++该学生信息已经删除!+++++++++')
print('++++++++输入1继续删除学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
del_stu()
else:
break
if none == 0:
print('++++++++++++不存在该学生!++++++++++++')
print('++++++++输入1继续删除学生信息++++++++')
print("++++++++输入其他指令返回主菜单+++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
del_stu()
else:
pass
# 声明查看班级所有学生信息函数
def find_all():
print('所有学生信息')
for x in Py1807:
print(x)
print("+++++++输入任何指令返回主菜单++++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str():
pass
# 声明查看指定学生平均成绩函数
def find_ave():
average = float(0)
none = 0
print('++++您选择了查看指定学生平均成绩+++++')
grades = str(input('!!!请输入指定学生姓名!!!:'))
for index1 in range(0,len(Py1807)):
if grades == str(Py1807[index1]['name']):
average =(Py1807[index1]['English']+Py1807[index1]['P.E']+Py1807[index1]['Art']+Py1807[index1]['Math'])/4
print(average) #取出各科成绩计算平均值并打印
print('++++++++输入1继续查看学生信息++++++++')
print("+++++++输入其他指令返回主菜单++++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_ave()
else:
break
if none == 0:
print('++++++++++++不存在该学生!++++++++++++')
print('++++++++输入1继续查看学生信息++++++++')
print("+++++++输入其他指令返回主菜单++++++++")
instruction2 = str(input("!!!请输入指令!!!:"))
if instruction2 == str(1):
find_ave()
else:
pass
#主菜单(根据指令调用之前封装好的函数)
while 1:
print('+++++++[欢迎进入学生管理系统]++++++++'
'\n+ 输入1添加学生信息 +'
'\n+ 输入2查看指定学生信息 +'
'\n+ 输入3删除指定学生信息 +'
'\n+ 输入4查看班级所有学生信息 +'
'\n+ 输入5查看指定学生平均成绩 +'
'\n+++++++++++++++++++++++++++++++++++++')
instruction1 = str(input('!!!请输入指令!!!:'))
if instruction1 == str(1):
add_stu()
elif instruction1 == str(2):
find_stu()
elif instruction1 ==str(3):
del_stu()
elif instruction1 == str(4):
find_all()
elif instruction1 ==str(5):
find_ave()
else:
print("+++++++++无效指令请重新输入!+++++++++")
网友评论