Python student grade management information management system (object-oriented) (Grade Management)

mission details

The project team received a new project to develop a "student information management system" for a certain school. After communicating with the customer, the main functions of the system were determined as shown in the figure below.

The entire student information management system mainly includes two modules: basic information management and student performance management.

The main functions of the basic information management module include adding, deleting, modifying, displaying student information and importing and exporting student data.

The main functions of the student performance management module include the highest score, lowest score and average score of the statistics course.

In the previous article, we have completed the functional module of student information management.

Python student performance management information management system (object-oriented) (student information)_Li Weiweiwiwi's blog-CSDN blog project team received a new project to develop a "student information management system" for a school. After communicating with the customer Communicate and determine the main functions of the system as shown in the figure below. The entire student information management system mainly includes two modules: basic information management and student performance management. The main functions of the basic information management module include adding, deleting, modifying, and displaying student information and importing and exporting student data. The main functions of the student performance management module include the highest score, lowest score, and average score of the statistics course. https://blog.csdn.net/agelee/article/details/126664530

Next, we will first improve the student information management function, add the function of file import and export of learning information, and also add the function of the student performance management submenu.

File import and export

StudentListContinue to add two functions for file import and export under the student information management class :

class StudentList:
    def __init__(self):
        self.stulist = []
	...
    #以下增加导入和导出学生信息功能
    def load(self,fn):
        #导入学生信息
        if os.path.exists(fn):
            try:
                with open(fn,'r',encoding = 'utf-8') as fp:
                    while True:
                        fs = fp.readline().strip('\n')
                        if not fs:
                            break
                        else:
                            stu = Student(*fs.split(','))
                            if self.__exists(stu.no):
                                print('该学号已存在')
                            else:
                                self.stulist.append(stu)
                print('导入完毕')
            except:
                print('error...') #要导入的文件不是utf-8编码,或是字段数不匹配等
        else:
            print('要导入的文件不存在')
        

    def save(self,fn):
        #导出学生信息
        with open(fn,'w',encoding = 'utf-8') as fp:
            for stu in self.stulist:
                fp.write(stu.no + ',')
                fp.write(stu.name + ',')
                fp.write(str(stu.chinese) + ',')
                fp.write(str(stu.math) + ',')                    
                fp.write(str(stu.english) + '\n')                    
            print("导出完毕")

We create a new csv file and enter the following content:

005,TEST02,87,65,99

006,TEST03,90,85,85

Then run the program and import this file data through the following menu

After the import is completed, enter the show command and we can see the relevant imported data:

Then we enter the save command to export the file:

Open the document as follows:

Student performance management module

According to our overall system architecture, we first modify the main menu and add scorefunctions corresponding to student statistics in the menu.

scoreprocess():

    def main(self):
        #主控函数               
        while True:
            print('学生信息管理系统V1.0'.center(24,'='))
            print('info  -------学生基本信息管理')
            print('score -------学生成绩统计')
            print('exit  -------退出系统')
            print(''.center(32,'='))
            s = input('main>').strip().lower()
            if s == 'info':
                self.infoprocess()
            elif s == 'score':
                self.scoreprocess()
            elif s == 'exit':
                break
            else:
                print('输入错误')   

Then we define a function scoreprocess()for student performance statistics:

 def scoreprocess(self):
        #学生成绩统计
        print('学生成绩统计'.center(24,'='))
        print('avg    --------课程平均分')
        print('max    --------课程最高分')
        print('min    --------课程最低分')        
        print('return --------返回')
        print(''.center(30,'='))
        while True:
            s = input('score>').strip().lower()
            if s == 'avg':                
                self.scoreavg()
            elif s == 'max':                
                self.scoremax()
            elif s == 'min':                
                self.scoremin()
            elif s == 'return':
                break
            else:
                print('输入错误')

Finally, define three functions for statistical average, highest and lowest scores:

 def scoreavg(self):
        #求课程平均分
        length = len(self.stulist)
        if length > 0:
            chinese_avg = sum([stu.chinese for stu in self.stulist])/length
            math_avg = sum([stu.math for stu in self.stulist])/length
            english_avg = sum([stu.english for stu in self.stulist])/length
            print('语文成绩平均分是:%.2f'%chinese_avg)
            print('数学成绩平均分是:%.2f'%math_avg)
            print('英语成绩平均分是:%.2f'%english_avg)
        else:
            print('尚没有学生成绩...')

    def scoremax(self):
        #求课程最高分
        if len(self.stulist) > 0:
            chinese_max = max([stu.chinese for stu in self.stulist])
            math_max = max([stu.math for stu in self.stulist])
            english_max = max([stu.english for stu in self.stulist])
            print('语文成绩最高分是:%d'%chinese_max)
            print('数学成绩最高分是:%d'%math_max)
            print('英语成绩最高分是:%d'%english_max)
        else:
            print('尚没有学生成绩...')

    def scoremin(self):
        #求课程最低分
        if len(self.stulist) > 0:
            chinese_min = min([stu.chinese for stu in self.stulist])
            math_min = min([stu.math for stu in self.stulist])
            english_min = min([stu.english for stu in self.stulist])
            print('语文成绩最低分是:%d'%chinese_min)
            print('数学成绩最低分是:%d'%math_min)
            print('英语成绩最低分是:%d'%english_min)
        else:
            print('尚没有学生成绩...')

Run the program:

Enter score:

The average score:

highest minute

Lowest score

Guess you like

Origin blog.csdn.net/agelee/article/details/126725221