菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

Python学生信息管理系统源代码

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:python教程 Python源码

Python学生信息管理系统源码是一个基于Python语言的简单系统,用于管理学生的基本信息,如姓名、学号、年龄等。该系统通常包括以下功能:添加学生信息、删除学生信息、修改学生信息、查询学生信息以及显示所有学生信息。源码中通常会使用类和对象来实现这些功能,例如创建一个学生类,包含学生的基本信息和方法。此外,还可能使用文件操作来存储和读取学生信息。总之,Python学生信息管理系统源码是一个实用的工具,可以帮助教师和管理员更高效地管理学生信息。

一个Python学生信息管理系统源码,包括录入学生信息、查找学生信息、删除学生信息、修改学生信息、排序学生信息、统计学生总数和显示所有学生信息等功能,最近帮朋友写的一个项目,有需要的朋友拿走。

开发环境要求本系统的软件开发及运行环境具体如下。操作系统:Windows 10。Python版本:Python 3.7.0。开发工具:Python IDLE。Python内置模块:os、re。

#_*_coding:utf-8_*_importre#导入正则表达式模块importos#导入操作系统模块filename="students.txt"#定义保存学生信息的文件名defmenu():#输出菜单print('''╔———————学生信息管理系统————————╗│││===============功能菜单===============││││1录入学生信息││2查找学生信息││3删除学生信息││4修改学生信息││5排序││6统计学生总人数││7显示所有学生信息││0退出系统││==========================================││说明:通过数字或↑↓方向键选择菜单│╚———————————————————————╝''')defmain():ctrl=True#标记是否退出系统while(ctrl):menu()#显示菜单option=input("请选择:")#选择菜单项option_str=re.sub("\D","",option)#提取数字ifoption_strin['0','1','2','3','4','5','6','7']:option_int=int(option_str)ifoption_int==0:#退出系统print('您已退出学生成绩管理系统!')ctrl=Falseelifoption_int==1:#录入学生成绩信息insert()elifoption_int==2:#查找学生成绩信息search()elifoption_int==3:#删除学生成绩信息delete()elifoption_int==4:#修改学生成绩信息modify()elifoption_int==5:#排序sort()elifoption_int==6:#统计学生总数total()elifoption_int==7:#显示所有学生信息show()'''1录入学生信息'''definsert():stdentList=[]#保存学生信息的列表mark=True#是否继续添加whilemark:id=input("请输入ID(如1001):")ifnotid:#ID为空,跳出循环breakname=input("请输入名字:")ifnotname:#名字为空,跳出循环breaktry:english=int(input("请输入英语成绩:"))python=int(input("请输入Python成绩:"))c=int(input("请输入C语言成绩:"))except:print("输入无效,不是整型数值....重新录入信息")continuestdent={"id":id,"name":name,"english":english,"python":python,"c":c}#将输入的学生信息保存到字典stdentList.append(stdent)#将学生字典添加到列表中inputMark=input("是否继续添加?(y/n):")ifinputMark=="y":#继续添加mark=Trueelse:#不继续添加mark=Falsesave(stdentList)#将学生信息保存到文件print("学生信息录入完毕!!!")#将学生信息保存到文件defsave(student):try:students_txt=open(filename,"a")#以追加模式打开exceptExceptionase:students_txt=open(filename,"w")#文件不存在,创建文件并打开forinfoinstudent:students_txt.write(str(info)+"\n")#按行存储,添加换行符students_txt.close()#关闭文件'''2查找学生成绩信息'''defsearch():mark=Truestudent_query=[]#保存查询结果的学生列表whilemark:id=""name=""ifos.path.exists(filename):#判断文件是否存在mode=input("按ID查输入1;按姓名查输入2:")ifmode=="1":id=input("请输入学生ID:")elifmode=="2":name=input("请输入学生姓名:")else:print("您的输入有误,请重新输入!")search()#重新查询withopen(filename,'r')asfile:#打开文件student=file.readlines()#读取全部内容forlistinstudent:d=dict(eval(list))#字符串转字典ifidisnot"":#判断是否按ID查ifd['id']==id:student_query.append(d)#将找到的学生信息保存到列表中elifnameisnot"":#判断是否按姓名查ifd['name']==name:student_query.append(d)#将找到的学生信息保存到列表中show_student(student_query)#显示查询结果student_query.clear()#清空列表inputMark=input("是否继续查询?(y/n):")ifinputMark=="y":mark=Trueelse:mark=Falseelse:print("暂未保存数据信息...")return'''3删除学生成绩信息'''defdelete():mark=True#标记是否循环whilemark:studentId=input("请输入要删除的学生ID:")ifstudentIdisnot"":#判断要删除的学生是否存在ifos.path.exists(filename):#判断文件是否存在withopen(filename,'r')asrfile:#打开文件student_old=rfile.readlines()#读取全部内容else:student_old=[]ifdel=False#标记是否删除ifstudent_old:#如果存在学生信息withopen(filename,'w')aswfile:#以写方式打开文件d={}#定义空字典forlistinstudent_old:d=dict(eval(list))#字符串转字典ifd['id']!=studentId:wfile.write(str(d)+"\n")#将一条学生信息写入文件else:ifdel=True#标记已经删除ififdel:print("ID为%s的学生信息已经被删除..."%studentId)else:print("没有找到ID为%s的学生信息..."%studentId)else:#不存在学生信息print("无学生信息...")break#退出循环show()#显示全部学生信息inputMark=input("是否继续删除?(y/n):")ifinputMark=="y":mark=True#继续删除else:mark=False#退出删除学生信息功能'''4修改学生成绩信息'''defmodify():show()#显示全部学生信息ifos.path.exists(filename):#判断文件是否存在withopen(filename,'r')asrfile:#打开文件student_old=rfile.readlines()#读取全部内容else:returnstudentid=input("请输入要修改的学生ID:")withopen(filename,"w")aswfile:#以写模式打开文件forstudentinstudent_old:d=dict(eval(student))#字符串转字典ifd["id"]==studentid:#是否为要修改的学生print("找到了这名学生,可以修改他的信息!")whileTrue:#输入要修改的信息try:d["name"]=input("请输入姓名:")d["english"]=int(input("请输入英语成绩:"))d["python"]=int(input("请输入Python成绩:"))d["c"]=int(input("请输入C语言成绩:"))except:print("您的输入有误,请重新输入。")else:break#跳出循环student=str(d)#将字典转换为字符串wfile.write(student+"\n")#将修改的信息写入到文件print("修改成功!")else:wfile.write(student)#将未修改的信息写入到文件mark=input("是否继续修改其他学生信息?(y/n):")ifmark=="y":modify()#重新执行修改操作'''5排序'''defsort():show()#显示全部学生信息ifos.path.exists(filename):#判断文件是否存在withopen(filename,'r')asfile:#打开文件student_old=file.readlines()#读取全部内容student_new=[]forlistinstudent_old:d=dict(eval(list))#字符串转字典student_new.append(d)#将转换后的字典添加到列表中else:returnascORdesc=input("请选择(0升序;1降序):")ifascORdesc=="0":#按升序排序ascORdescBool=False#标记变量,为False表示升序排序elifascORdesc=="1":#按降序排序ascORdescBool=True#标记变量,为True表示降序排序else:print("您的输入有误,请重新输入!")sort()mode=input("请选择排序方式(1按英语成绩排序;2按Python成绩排序;3按C语言成绩排序;0按总成绩排序):")ifmode=="1":#按英语成绩排序student_new.sort(key=lambdax:x["english"],reverse=ascORdescBool)elifmode=="2":#按Python成绩排序student_new.sort(key=lambdax:x["python"],reverse=ascORdescBool)elifmode=="3":#按C语言成绩排序student_new.sort(key=lambdax:x["c"],reverse=ascORdescBool)elifmode=="0":#按总成绩排序student_new.sort(key=lambdax:x["english"]+x["python"]+x["c"],reverse=ascORdescBool)else:print("您的输入有误,请重新输入!")sort()show_student(student_new)#显示排序结果'''6统计学生总数'''deftotal():ifos.path.exists(filename):#判断文件是否存在withopen(filename,'r')asrfile:#打开文件student_old=rfile.readlines()#读取全部内容ifstudent_old:print("一共有%d名学生!"%len(student_old))else:print("还没有录入学生信息!")else:print("暂未保存数据信息...")'''7显示所有学生信息'''defshow():student_new=[]ifos.path.exists(filename):#判断文件是否存在withopen(filename,'r')asrfile:#打开文件student_old=rfile.readlines()#读取全部内容forlistinstudent_old:student_new.append(eval(list))#将找到的学生信息保存到列表中ifstudent_new:show_student(student_new)else:print("暂未保存数据信息...")#将保存在列表中的学生信息显示出来defshow_student(studentList):ifnotstudentList:print("(o@.@o)无数据信息(o@.@o)\n")returnformat_title="{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^10}"print(format_title.format("ID","名字","英语成绩","Python成绩","C语言成绩","总成绩"))format_data="{:^6}{:^12}\t{:^12}\t{:^12}\t{:^12}\t{:^12}"forinfoinstudentList:print(format_data.format(info.get("id"),info.get("name"),str(info.get("english")),str(info.get("python")),str(info.get("c")),str(info.get("english")+info.get("python")+info.get("c")).center(12)))if__name__=="__main__":main()


评论
建站知识
建站知识
使用技巧
调试安装
运营推广