侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Python实现学生成绩管理系统

Python  /  管理员 发布于 7年前   349

本文实例为大家分享了Python实现学生成绩管理系统的具体代码,供大家参考,具体内容如下

基本功能:

输入并存储学生的信息:通过输入学生的学号、姓名、和分数,然后就可以把数据保存在建立的student文件里面。

打印学生的所有信息:通过一个打印函数就可以把所有的信息打印在屏幕上。

修改学生信息:这个功能首先通过查询功能查询出该学生是否存在,如果存在就对该学生的信息进行修改,如果不存在则返回到主界面。

删除学生信息:该功能是对相应的学生进行删除操作,如果学生存在就查找到进行删除。

按学生成绩进行排序: 这个功能是按照学生的成绩进行排序,对学生的信息进行操作。

查找学生信息:这个功能通过输入学号,查找该学生的信息,如果有该学号就输出该学生的信息,没有该学号就提示输入的学号不存在。

初始化功能

系统在开始使用之前先进行初始化功能,判断students.txt文件中是否保存的有学生的信息,如果有就把文件的内容读取出来,供接下来的操作使用,如用没有就初始化一个空的列表,用来保存用户的输入,程序中接下来的所有数据都会保存在该列表中相当与一个数据缓冲区。

首先是打开文件操作,对文件中的内容进行读取操作,由于在文件中保存的内容是由空格进行分割的,并且每一个学生的信息都占用一行,首先读出所有的内容,先进行按照换行进行分割,得到每个人的信息,然后再对每个人的信息进行安装空格分隔,得到每个人的详细信息包括用户的姓名,学号,成绩。

def Init(stulist): #初始化函数  print "初始化......"  file_object = open('students.txt', 'r')  for line in file_object:  stu = Student()  line = line.strip("\n")  s = line.split(" ")  stu.ID = s[0]  stu.name = s[1]  stu.score = s[2]  stulist.append(stu) print "初始化成功!" 

成绩排序实现

这部分代码是按照学生成绩的高低进行排序,在实现的时候,首先是把所有人的成绩放到一个列表里面然后使用插入排序,按照成绩的大小对StuList中保存的学生信息的地址进行排序

def Sort(stulist): #按学生成绩排序 Stu = [] sum_count = [] for li in stulist: temp = [] temp.append(li.ID) temp.append(li.name) temp.append(int(li.score1)) temp.append(int(li.score2)) temp.append(int(li.score3)) temp.append(int(li.sum)) sum_count.append(int(li.sum)) Stu.append(temp) #print sum_count #print Stu; #print stulist insertSort(sum_count, stulist) #print stulist; display(stulist)def insertSort(a, stulist):  for i in range(len(a)-1):  #print a,i  for j in range(i+1,len(a)):  if a[i]<a[j]:  temp = stulist[i]  stulist[i] = stulist[j]  stulist[j] = temp

界面截图如下:

源码:

# -*- coding: UTF-8 -*-import osimport reimport numpy as npclass Student: #定义一个学生类 def __init__(self): self.name = '' self.ID ='' self.score1 = 0 self.score2 = 0 self.score1 = 0 self.sum = 0def searchByID(stulist, ID): #按学号查找看是否学号已经存在 for item in stulist: if item.ID == ID: return Truedef Add(stulist,stu): #添加一个学生信息 if searchByID(stulist, stu.ID) == True: print"学号已经存在!" return False stulist.append(stu) print stu.name,stu.ID, stu.score1, stu.score2, stu.score3, stu.sum; print "是否要保存学生信息?" nChoose = raw_input("Choose Y/N") if nChoose == 'Y' or nChoose == 'y': file_object = open("students.txt", "a") file_object.write(stu.ID) file_object.write(" ") file_object.write(stu.name) file_object.write(" ") file_object.write(str(stu.score1)) file_object.write(" ") file_object.write(str(stu.score2)) file_object.write(" ") file_object.write(str(stu.score3)) file_object.write(" ") file_object.write(str(stu.sum)) file_object.write("\n") file_object.close() print u"保存成功!"def Search(stulist, ID): #搜索一个学生信息 print u"学号 姓名 语文 数学 英语 总分" count = 0 for item in stulist: if item.ID == ID: print item.ID, '\t' ,item.name,'\t', item.score1,'\t',item.score2, '\t', item.score3, '\t',item.sum break count = 0 if count == len(stulist): print "没有该学生学号!"def Del(stulist, ID): #删除一个学生信息 count = 0 for item in stulist: if item.ID == ID: stulist.remove(item) print "删除成功!" break count +=1 # if count == len(stulist): # print "没有该学生学号!" file_object = open("students.txt", "w") for stu in stulist: print stu.ID, stu.name, stu.score1,stu.score2, stu.score3, stu.sum file_object.write(stu.ID) file_object.write(" ") file_object.write(stu.name) file_object.write(" ") file_object.write(str(stu.score1)) file_object.write(" ") file_object.write(str(stu.score2)) file_object.write(" ") file_object.write(str(stu.score3)) file_object.write(" ") file_object.write(str(stu.sum)) file_object.write("\n") file_object.close() # print "保存成功!" file_object.close()def Change(stulist, ID): count = 0 for item in stulist: if item.ID == ID: stulist.remove(item) file_object = open("students.txt", "w") for stu in stulist: #print li.ID, li.name, li.score file_object.write(stu.ID) file_object.write(" ") file_object.write(stu.name) file_object.write(" ") file_object.write(str(stu.score1)) file_object.write(" ") file_object.write(str(stu.score2)) file_object.write(" ") file_object.write(str(stu.score3)) file_object.write(" ") file_object.write(str(stu.sum)) file_object.write("\n") # print "保存成功!" file_object.close() stu = Student() stu.name = raw_input("请输入学生的姓名") while True: stu.ID = raw_input("请输入学生的ID") p = re.compile('^[0-9]{3}$') if p.match(stu.ID):  break else:  print "输入的有错误!" while True: stu.score1 = int(raw_input("请输入学生语文成绩")) if stu.score1 <= 100 and stu.score1 > 0 :  break else:  print "输入的学生成绩有错误!" while True: stu.score2 = int(raw_input("请输入学生数学成绩")) if stu.score2 <= 100 and stu.score2 > 0 :  break else:  print "输入的学生成绩有错误!" while True: stu.score3 = int(raw_input("请输入学生英语成绩")) if stu.score3 <= 100 and stu.score3 > 0 :  break else:  print "输入的学生成绩有错误!" stu.sum = stu.score1 + stu.score2 + stu.score3 Add(stulist,stu)def display(stulist): #显示所有学生信息 print u"学号 姓名 语文 数学 英语 总分" for item in stulist: print item.ID, '\t' ,item.name,'\t', item.score1,'\t',item.score2, '\t', item.score3, '\t',item.sumdef Sort(stulist): #按学生成绩排序 Stu = [] sum_count = [] for li in stulist: temp = [] temp.append(li.ID) temp.append(li.name) temp.append(int(li.score1)) temp.append(int(li.score2)) temp.append(int(li.score3)) temp.append(int(li.sum)) sum_count.append(int(li.sum)) Stu.append(temp) #print sum_count #print Stu; #print stulist insertSort(sum_count, stulist) #print stulist; display(stulist)def insertSort(a, stulist):  for i in range(len(a)-1):  #print a,i  for j in range(i+1,len(a)):  if a[i]<a[j]:  temp = stulist[i]  stulist[i] = stulist[j]  stulist[j] = temp  #return a def Init(stulist): #初始化函数 print "初始化......" file_object = open('students.txt', 'r') for line in file_object: stu = Student() line = line.strip("\n") s = line.split(" ") stu.ID = s[0] stu.name = s[1] stu.score1 = s[2] stu.score2 = s[3] stu.score3 = s[4] stu.sum = s[5] stulist.append(stu) file_object.close() print "初始化成功!" main()def main(): #主函数 该程序的入口函数 while True: print "*********************" print u"--------菜单---------" print u"增加学生信息--------1" print u"查找学生信息--------2" print u"删除学生信息--------3" print u"修改学生信息--------4" print u"所有学生信息--------5" print u"按照分数排序--------6" print u"退出程序------------0" print "*********************" nChoose = raw_input("请输入你的选择:") if nChoose == "1": stu = Student() stu.name = raw_input("请输入学生的姓名") while True: stu.ID = raw_input("请输入学生的ID") p = re.compile('^[0-9]{3}$') if p.match(stu.ID):  break else:  print "输入的有错误!" while True: stu.score1 = int(raw_input("请输入学生语文成绩")) if stu.score1 <= 100 and stu.score1 > 0 :  break else:  print "输入的学生成绩有错误!" while True: stu.score2 = int(raw_input("请输入学生数学成绩")) if stu.score2 <= 100 and stu.score2 > 0 :  break else:  print "输入的学生成绩有错误!" while True: stu.score3 = int(raw_input("请输入学生英语成绩")) if stu.score3 <= 100 and stu.score3 > 0 :  break else:  print "输入的学生成绩有错误!" stu.sum = stu.score1 + stu.score2 + stu.score3 Add(stulist,stu) if nChoose == '2': ID = raw_input("请输入学生的ID") Search(stulist, ID) if nChoose == '3': ID = raw_input("请输入学生的ID") Del(stulist, ID) if nChoose == '4': ID = raw_input("请输入学生的ID") Change(stulist, ID) if nChoose == '5': display(stulist) if nChoose == '6': Sort(stulist) if nChoose == '0': breakif __name__ == '__main__': stulist =[]Init(stulist)

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    python实现外卖信息管理系统
    下一条:
    名片管理系统python版
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客