python实现学生管理连串,Python完结学生战表管理

作者: 韦德国际1946手机版  发布:2019-06-01

正文实例为大家享受了python学生管理类别的求实代码,供大家参谋,具体内容如下

python学生管理种类代码达成,python学生处理系列

正文实例为我们分享了python学生管理类别的切实代码,供大家参谋,具体内容如下

python实现学生管理连串,Python完结学生战表管理种类。类

class Student: 
  stuID = "" 
  name = "" 
  sex = "M" 
  classID = "NULL" 

  #set ID  
  def setStuID(self,stuID): 
    self.stuID = stuID 

  def setName(self,name): 
    self.name = name 

  def setSex(self,sex): 
    self.sex = sex 

  def setClassID(self,classID): 
    self.classID = classID 

  def getStuId(self): 
    return self.stuID 

  def getName(self): 
    return self.name 

  def getSex(self): 
    return self.sex 

  def getClassID(self): 
    return self.classID 

主函数

import os 
import re 
import sys 
import string 
import student 

#save file 
global FILEPATH 
FILEPATH = "student.db" 
#temporary file  
global TEMPFILE 
TEMPFILE = "temp.db" 

#This is menu 
def menu(): 
  while True : 
    print "1.Add a student information" 
    print "2.Query student information" 
    print "3.Delete a student information" 
    print "0.Quit" 
    opt = raw_input("Select:") 
    if opt == "1": 
      while True: 
        addStudent() 
        opt2 = raw_input("Continue Add(Y/N)?:") 
        if opt2 == "Y" or opt2 == "y" or opt2 == "": 
          continue 
        else: 
          break 
    elif opt == "2": 
      while True: 
        query() 
        opt2 = raw_input("Continue Query(Y/N)?:") 
        if opt2 == "Y" or opt2 == "y" or opt2 == "": 
          continue 
        else: 
          break       
    elif opt == "3": 
      while True: 
        delMenu() 
        opt2 = raw_input("Continue Delete(Y/N)?:") 
        if opt2 == "Y" or opt2 == "y" or opt2 == "": 
          continue 
        else: 
          break        
    elif opt == "0" : 
      exitProgram()   
      break  
    else: 
      print "Error input" 

#Add a student 
def addStudent() : 
  stu = student.Student() 
  while True: 
    stuID = raw_input("ID(001-999):") 
    #match ID 001-999 
    p = re.match("^[0-9]{3}$", stuID) 
    if p : 
      if stuID == "000": 
        print "ID must be 001-999" 
        continue 
      if isIDExist(stuID): 
        print "ID = %s already exist!" % stuID 
        continue 
      else :   
        stu.setStuID(stuID) 
      break 
    else: 
      print "ID must be 001-999" 

  while True:     
    stuName = raw_input("Name(a-z,A-Z,5 char):") 
    #match name a-z A-Z 5 char 
    p = re.match("^[a-zA-Z]{1,5}$",stuName) 
    if p : 
      stu.setName(stuName) 
      break 
    else : 
      print "Name format error must a-z,A-Z,within 5 char" 

  while True:   
    stuSex = raw_input("Sex(default is M):") 
    #default value 
    if stuSex == "": 
      stu.setSex("M") 
      print "Sex:M" 
      break 
    if stuSex =="M" or stuSex == "m": 
      stu.setSex(string.upper(stuSex)) 
      break        
    #if stuSex == "M" or stuSex == "m" || stuSex == "F" stuSex == "f": 
    p = re.match("^M|m|F|f$",stuSex) 
    if p : 
      stu.setSex(string.upper(stuSex)) 
      break 
    else : 
      print "Sex(M/f)" 

  while True: 
    stuClass = raw_input("Class(01-99):") 
    #default value 
    if stuClass == "": 
      stu.setClassID("NULL") 
      print "CLASS:NULL" 
      break 
    #match 00-99 
    p = re.match("^[0-9]{2}$",stuClass) 
    if p : 
      #get rid of 00 
      if stuClass == "00": 
        print "Class must 01-99" 
        continue 
      stu.setClassID(stuClass) 
      break 
    else: 
      print "Class must 01-99" 
  #save to file     
  file1 = open(FILEPATH,"a") 
  print "IDtNAMEtSEXtCLASS" 
  print stu.getStuId(),"t",stu.getName(),"t",stu.getSex(),"t",stu.getClassID() 
  file1.write(stu.getStuId() "t" stu.getName() "t" stu.getSex() "t" stu.getClassID() "n") 
  print "Add student success!" 
  file1.close() 

#Delete student menu   
def delMenu(): 
  print "1.Delete by ID" 
  print "2.Delete contains ID" 
  opt = raw_input("Select:") 
  if opt == "1": 
    delStudentByID() 
  elif opt == "2": 
    delStudentContainsID() 
  else: 
    print "Error input"   

#Delete contains id     
def delStudentContainsID(): 
  contID = raw_input("ID:") 
  if getInfoContainsID(contID)==0 : 
    print "Can't find ID contains "%s" student" % contID 
    return 
  opt = raw_input("Are you sure delete all(Y/N):") 
  if not opt == "y" or opt == "Y": 
    return    
  f = open(FILEPATH,"r") 
  tmp = open(TEMPFILE,"a") 
  i=0 
  for eachLine in f: 
    items = eachLine.split("t") 
#    if not re.match(contID, items[0]): 
    if items[0].count(contID) ==0: 
      tmp.write(eachLine) 
    else:  
      i =1    
  f.close() 
  tmp.close() 
  os.remove(FILEPATH) 
  os.rename(TEMPFILE, FILEPATH) 
  print "Deleted %d data" % i 

#get contains ID information          
def getInfoContainsID(stuID): 
  f = open(FILEPATH) 
  i=0 
  for eachLine in f: 
    items = eachLine.split("t") 

    if not items[0].count(stuID) ==0: 
#    if re.match(stuID,items[0]): 
      i =1 
      if i==1: 
        print "IDtNAMEtSEXtCLASS" 
      print eachLine, 
  if i==0: 
    return 0 
  else : 
    return i 
  f.close() 

#Delete student by ID   
def delStudentByID(): 
  delID = raw_input("Delete ID:") 
  if not isIDExist(delID) : 
    print "Can't find ID = %s student information" % delID 
    return  

  getInfoByID(delID) 
  opt = raw_input("Are you sure delete it(Y/N):") 
  if not (opt == "Y" or opt == "y"): 
    return 

  f = open(FILEPATH,"r") 
  tmp = open(TEMPFILE,"a") 

  for eachLine in f: 
    split = eachLine.split("t")     
    if not delID == split[0]: 
      tmp.write(eachLine)            
  tmp.close() 
  f.close() 
  os.remove(FILEPATH) 
  os.rename(TEMPFILE, FILEPATH) 
  print "Delete success!" 

#Query menu   
def query(): 
  print "1.Query student by ID" 
  print "2.Query all students" 
  opt = raw_input("Select:") 
  if opt == "1": 
    queryByID() 
  elif opt == "2": 
    queryAll() 
  #default is query all   
  elif opt == "": 
    queryAll()   
  else : 
    print "Error Input!"   

#query ID exist 
def isIDExist(ID): 
  f = open(FILEPATH) 
  flag = 0 
  for eachline in f: 
    temp = eachline.split("t") 
    if temp[0] == ID: 
      flag =1 
  f.close() 
  if flag == 0 : 
    return False 
  else: 
    return True 

#get information by ID for delete student    
def getInfoByID(stuID): 
  f = open(FILEPATH) 
  i=0 
  for eachLine in f: 
    items = eachLine.split("t") 
    if items[0] == stuID: 
      i =1 
      if i==1: 
        print "IDtNAMEtSEXtCLASS" 
      print eachLine   
  f.close()      

#Query student by ID 
def queryByID(): 
  queryID = raw_input("ID:") 
  f = open(FILEPATH) 
#  lines = f.readlines() 
#  print lines[0].strip() 
#  for line in lines: 
#    a = line.split() 
#    if queryID == a[1].strip(): 
#      print line.strip() 
  flag = 0 
  for eachline in f: 
    #split by "t" get as C array temp[4] 
    temp = eachline.split("t") 
#    print temp[0] , temp[1] , temp[2] , temp[3] 
    if temp[0] == queryID: 
      flag =1 
      if flag == 1: 
        print "IDtNAMEtSEXtCLASS" 
      print eachline, 
  if flag == 0 : 
    print "Can't find ID = %s student information" % queryID     
  f.close() 
#  f = open(FILEPATH) 
#  readLines = f.readlines() 

#  for eachLine in f: 
#    eachLine 
#         
#    if eachLine == queryID: 
#      print eachLine 
#  f.close() 

#Query all students   
def queryAll(): 
  f = open(FILEPATH,"r") 
  i=0 
  for eachLine in f: 
    i =1 
    if i==1: 
      print "IDtNAMEtSEXtCLASS" 
    print eachLine, 
  f.close() 
  if i==0: 
    print "No data!" 

def exitProgram(): 
  print "Thank you Bye!" 
#  sys.exit() 

def init(): 
  if os.path.exists(FILEPATH) : 
    print "Load file successful" 
  else: 
    try: 
      f = open(FILEPATH,"w") 
    except Exception: 
      print "Can't open file" 
      sys.exit() 
    finally: 
      f.close() 

if __name__ == '__main__': 
  init() 
  menu() 

以上就是本文的全部内容,希望对我们的求学抱有扶助,也冀望大家多多支持帮客之家。

本文实例为大家大快朵颐了python学生管理体系的求实代码,供我们仿效,具体内容如下 类 cla...

python完结学生管理种类,python学生处理种类

python写的轻巧的学员处理体系,演习python语法。

能够运作在windows和linux下,python 二.柒。

#!/usr/local/bin/python 
# -*- coding:utf-8 -*- 

import os 
import re 

#定义学生类 
class Student: 
 def __init__(self): 
  self.name = '' 
  self.ID = '' 
  self.score = 0 

#根据学生分数进行从大到小的冒泡排序 
def BuddleSortByScore( stulist ): 
 n = len( stulist ) 
 for i in range( n ): 
  for j in range( n - i - 1): 
   if stulist[j].score < stulist[j 1].score: 
    #tmp = stulist[j 1] 
    #stulist[j 1] = stulist[j] 
    #stulist[j] = tmp 
    stulist[j],stulist[j 1] = stulist[j 1],stulist[j] 

#按顺序输出所有学生的信息 
def PrintAllStudentInfo( stulist ): 
 print u"______________________学生列表_______________" 
 for i in range( len(stulist) ): 
  print u"姓名:" , 
  print stulist[i].name, 
  print " " , 
  print u"学号:" , 
  print stulist[i].ID , 
  print " " , 
  print u"分数:" , 
  print stulist[i].score 
 print "____________________________________________" 

#增加一个学生,增加成功返回True,否则返回False 
def Add( stulist , stu ): 
 if searchByID( stulist , stu.ID ) == 1: 
  print u"此ID已经存在!" 
  return False 
 stulist.append( stu ) 

 #给出是否保存更新数据的选择 
 print "Do you want to save the result ?" 
 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.score) ) 
  file_object.write( "rn" ) 
  file_object.close() 
  return True 
 else: 
  stulist.remove(stu) 

#根据ID删除一个学生的信息,删除成功则返回True,否则返回false 
def DeleteByID( stulist , ID ): 
 for stu in stulist: 
  if stu.ID == ID: 
   stulist.remove( stu ) 

   #选择是否保存已经改变的内容 
   print "Do you want to save the changed result ?" 
   nChoose = raw_input("Choose:Y/N:") 

   if nChoose == 'Y' or nChoose == 'y': 
    file_object = open("students.txt" , "w ") 
    for stu2 in stulist: 
     file_object.write(stu2.ID) 
     file_object.write(" ") 
     file_object.write(stu2.name) 
     file_object.write(" ") 
     file_object.write(str(stu2.score)) 
     file_object.write("rn") 
    file_object.close() 
    print u"删除成功!" 
   return True 
 print u"删除失败!" 
 return False 


#根据姓名删除一个学生的信息,删除成功返回True,否则返回False 
def DeleteByName( stulist , name ): 
 pos = searchByName( stulist , name ) 
 if pos != -1: 
  del stulist[pos] 

  #选择是否保存已经改变的内容 
  print "Do you want to save the changed result ?" 
  nChoose = raw_input("Choose:Y/N:") 

  if nChoose == 'Y' or nChoose == 'y': 
    file_object = open("students.txt" , "w ") 
    for stu2 in stulist: 
     file_object.write(stu2.ID) 
     file_object.write(" ") 
     file_object.write(stu2.name) 
     file_object.write(" ") 
     file_object.write(str(stu2.score)) 
     file_object.write("rn") 
    file_object.close() 
    print u"删除成功!" 
  return True 
 else: 
  print u"删除失败!" 
  print pos 
  return False 


#根据学号查找一个学生是否存在,存在返回学生在列表中的下标,否则返回-1 
def searchByID( stulist , ID ): 
 for i in range( len(stulist) ): 
  if stulist[i].ID == ID: 
   print u"姓名:" , 
   print stulist[i].name , 
   print " " , 
   print u"学号:" , 
   print stulist[i].ID , 
   print " " , 
   print u"分数:" , 
   print stulist[i].score 
   return i 
 return -1 

#根据姓名查找一个学生是否存在,存在返回学生在列表中的下标,否则返回-1 
def searchByName( stulist , name ): 
 for i in range( len(stulist) ): 
  if stulist[i].name == name: 
   print u"姓名:" , 
   print stulist[i].name , 
   print " " , 
   print u"学号:" , 
   print stulist[i].ID , 
   print " " , 
   print u"分数:" , 
   print stulist[i].score 
   return i 
 return -1 

#初始化,读取文件,更新学生信息 
def Init( stulist ): 
 print u"初始化......" 

 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 u"初始化成功!" 


#查找菜单 
def QueryMenu( stulist ): 
 while True: 
  print "******************************" 
  print u"根据学生的学号进行查找-------1" 
  print u"根据学生的姓名进行查找-------2" 
  print u"离开查找模块----------------3" 
  print "******************************" 

  nChoose = raw_input("请输入你的选择") 

  if nChoose == "1": 
   ID = raw_input("请输入你要输入查找的ID:") 
   searchByID( stulist , ID ) 
  elif nChoose == "2": 
   name = raw_input("请输入你要查找的姓名:") 
   searchByName( stulist , name ) 
  elif nChoose == "3": 
   return 
  else: 
   print u"选择输入错误,请重新输入!" 

#删除模块 
def DeleteMenu( stulist ): 
 while True: 
  print "*****************************" 
  print u"根据学生的学号进行删除------1" 
  print u"根据学生的姓名进行删除------2" 
  print u"离开删除模块---------------3" 
  print "******************************" 

  nChoose = raw_input("请进行选择:") 

  if nChoose == "1": 
   ID = raw_input("请输入你要删除的ID:") 
   DeleteByID( stulist , ID ) 
  elif nChoose == "2": 
   name = raw_input("请输入你要删除的姓名:") 
   DeleteByName( stulist , name ) 
  elif nChoose == "3": 
   return 
  else: 
   print u"您的选择有误,请重新输入!" 


#菜单 
def menu( stulist ): 
 while True: 
  print "***********************" 
  print u"--------菜单------------" 
  print u"增加学生信息---------1" 
  print u"查找一个学生的信息----2" 
  print u"删除一个学生的信息----3" 
  print u"输出所有学生的信息----4" 
  print u"根据分数排序---------5" 
  print u"退出程序-------------6" 
  print "------------------------" 
  print "************************" 

  nChoose = raw_input("请输入你的选择:") 

  if nChoose == "1": 
   stu = Student() 
   stu.name = raw_input("请输入学生的姓名:") 

   #匹配学生ID是否满足0--9中的数字 
   while True: 
    stu.ID = raw_input("请输入学生的ID:") 
    #创建编译一个正则表达式的模板 
    p = re.compile( '^[0-9]{3}$' ) 
    if p.match( stu.ID ): 
     break 
    else: 
     print "学生的ID输入错误,正确形式应该为0--9之间的三位数字!" 

   #匹配学生的分数是否满足0--100之间 
   while True:  
    stu.score = eval( raw_input("请输入学生的分数:") ) 
    #利用普通的符号来判断分数是否符合标准 
    #if stu.score >= 0 and stu.score <= 100: 
    # break 
    #利用正则表达式来判断分数是否符合标准 
    if re.match( "^[0-9]" ,str(stu.score) ) and stu.score<=100 and    stu.score >= 0 : 
     break 
    else: 
     print u"分数不满足实际情况,应该为0--100之间的数字!" 

   if Add( stulist , stu ) == 1: 
    print u"学生信息增加成功!" 
   else: 
    print u"学生信息增加失败!" 
  elif nChoose == "2": 
   QueryMenu( stulist ) 
  elif nChoose == "3": 
   DeleteMenu( stulist ) 
  elif nChoose == "4": 
   PrintAllStudentInfo( stulist ) 
  elif nChoose == "5": 
   BuddleSortByScore( stulist ) 

   print "Do you want to save the sorted result?" 
   choose = raw_input("please input your choice:Y/N:") 
   if choose == 'Y' or choose == 'y': 
    file_object = open("students.txt","w ") 
    for stu2 in stulist: 
     file_object.write(stu2.ID) 
     file_object.write(" ") 
     file_object.write(stu2.name) 
     file_object.write(" ") 
     file_object.write(str(stu2.score)) 
     file_object.write("rn") 
  elif nChoose == "6": 
   return 
  else: 
   print u"输入有误,请重新输入!" 

#测试函数部分 
if __name__ == '__main__': 
 #定义一个列表用来存储所有学生的信息 
 stulist = [] 

 #初始化,从文件中读取信息 
 Init( stulist ) 

 #菜单函数 
 menu( stulist ) 

运营供给读写文件Students.txt。文件格式如下图:

图片 1

越来越多学习质感请关切专项论题《管理种类开拓》。

如上便是本文的全体内容,希望对咱们的求学抱有支持,也愿意大家多多帮忙帮客之家。

python写的大约的上学的小孩子管理种类,练习python语法。 能够运作在windows和linux下,python 2.7。 #!/usr/l...

Python完成学生战绩处理种类,python

正文实例为咱们享用了Python完结学生战表管理种类的实际代码,供我们参谋,具体内容如下

基本成效:

输入并积累学生的音信:通过输入学生的学号、姓名、和分数,然后就足以把数量保存在建设构造的student文件之中。

打字与印刷学生的保有新闻:通过2个打字与印刷函数就可以把具备的新闻打字与印刷在显示器上。

修改学生新闻:这几个意义首先通过询问功用查询出该学员是或不是存在,倘若存在就对该学生的新闻进行改动,倘若不设有则赶回到主分界面。

删去学生音讯:该意义是对相应的上学的小孩子展开删除操作,假使学员存在就查找到实行删减。

按学生战绩进行排序: 这一个效应是遵照学生的实际业绩举办排序,对学生的消息实行操作。

检索学生新闻:那么些功能通过输入学号,查找该学员的音信,如若有该学号就输出该学生的音讯,未有该学号就提示输入的学号不设有。

初步化成效

系统在起首运用从前先进行起先化功用,剖断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

分界面截图如下:

图片 2

源码:

# -*- coding: UTF-8 -*-

import os
import re
import numpy as np

class Student: #定义一个学生类
 def __init__(self):
 self.name = ''
 self.ID =''
 self.score1 = 0
 self.score2 = 0
 self.score1 = 0
 self.sum = 0


def searchByID(stulist, ID): #按学号查找看是否学号已经存在
 for item in stulist:
 if item.ID == ID:
  return True

def 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.sum

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 
 #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':
  break

if __name__ == '__main__':
 stulist =[]
Init(stulist)

更加的多读书资料请关心专项论题《管理系列开垦》。

如上正是本文的全体内容,希望对我们的读书抱有支持,也指望我们多多扶助帮客之家。

本文实例为我们享受了Python完成学生战绩管理体系的切实可行代码,供我们参考,具体内容如下 基本功效:...

本文由韦德国际1946发布于韦德国际1946手机版,转载请注明出处:python实现学生管理连串,Python完结学生战表管理

关键词: 伟德BV1946