Python Implementation of Student Management System of Object Oriented Edition

  • 2021-11-13 08:18:37
  • OfStack

In this paper, we share the specific code of Python to realize the student management system for your reference. The specific contents are as follows

To realize the transition from process-oriented to object-oriented, by changing the previous student management system to realize object-oriented, it also proves that process-oriented can be perfectly transitioned to object-oriented, thus making a step forward optimization for future program progress, which is convenient for future program changes.

The complete code is as follows:

Code in the student_main module


import student_tools


class Student(student_tools.StudentT):

    def __init__(self):
        self.user=['wangtaotao']
        self.pwd=['123456']
        student_tools.StudentT.__init__(self)

    # Login 
    def denglu(self):
        users = input(" Please enter your user name :")
        pwds = input(" Please enter your password :")
        if users in self.user and pwds in self.pwd:
            self.student()
        else:
            print(" The account number or password is incorrect, please re-enter it ")

    # Registration 
    def zhuce(self):
        users=input(" Please enter the user name you want to register :")
        pwds=input(" Please enter the password you want to register :")
        self.user.append(users)
        self.pwd.append(pwds)
        print()
        print(" Successful registration !")
        print()

    # Login interface 
    def dljiemian(self):

        while True:
            print("---------------------------")
            print("     Login interface of student management system  V1.0  ")
            print("                           ")
            print("        1: Deng     Record            ")
            print("        2: Note     Volume            ")
            print("        3: Retreat     Out            ")
            print("                           ")
            print("---------------------------")
            xx=input(" Please enter your selection :")
            #1. Login 
            if xx=='1':
                self.denglu()
            elif xx=='2':
            #2. Registration 
                self.zhuce()
            elif xx=='3':
            #3. Quit 
                print()
                print(" Successful exit !")
                print()
                break
            else:
                print(" Enter error, please re-enter ")


    # Student management system 
    def student(self):
        #  Call student_tools Read File Function in Module 
        super().read_file()
        while True:
            # Call student_tools Interface functions in modules 
            super().jiemian()

            x=input(" Please enter your selection :")
            # Add Students 
            if x=='1':
                super().add()
            # Delete students 
            elif x=='2':
                super().dele()
            # Modify students 
            elif x=='3':
                super().xiugai()
            # Enquire about students 
            elif x=='4':
                super().find()
            # Show all students 
            elif x=='5':
                super().showall()
            # Save data to a file 
            elif x=='6':
                super().save_file()
            # Quit the student management system , Back up 1 Layer login interface system 
            elif x=='7':
                print()
                print(" Successfully quit the student management system !")
                break
            else:
                print()
                print(" Enter error, please re-enter ")
                print()

    # Call the first executed login interface function 
if __name__=='__main__':
    wtt=Student()
    wtt.dljiemian()

Code in the student_tools module


import os


class StudentT(object):

    def __init__(self):
        self.student_list=[]
        self.student_dict={}


    # Student management system interface 
    @staticmethod
    def jiemian():
        print("---------------------------")
        print("       Student management system  V1.0")
        print("                           ")
        print("      1: Add Students "            )
        print("      2: Delete students "            )
        print("      3: Modify students "            )
        print("      4: Enquire about students "            )
        print("      5: Show all students "         )
        print("      6: Save data "            )
        print("      7: Exit the system "            )
        print("                           ")
        print("---------------------------")


    # Add Students 
    def add(self):
        name=input(" Please enter the name of the student :")
        cls=input(" Please enter a student class :")
        age=input(" Please enter the age of the student :")
        phone=input(" Please enter the student's mobile phone number :")
        addr=input(" Please enter the student's home address :")

        self.student_dict={"name":name,"class":cls,"age":age,"phone":phone,"address":addr}

        self.student_list.append(self.student_dict)
        print()
        print("----- Add Student Information Interface -----")
        print()
        print(" Name \t\t"," Class \t\t"," Age \t\t"," Telephone number \t\t"," Home address \t\t")
        for student_dict_1 in self.student_list:
            print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                                 student_dict_1["class"],
                                                 student_dict_1["age"],
                                                 student_dict_1["phone"],
                                                 student_dict_1["address"]))
        print()
        print(" Successful entry !")
        print()

    # Delete students 
    def dele(self):
        name_del=input(" Please enter the name of the student you want to delete :")
        for student_dict_1 in self.student_list:
            if name_del in student_dict_1["name"]:
                self.student_list.remove(student_dict_1)
                print()
                print(" Delete %s Information success !" % name_del)
                print()
                break
        else:
            print()
            print(" The student name you entered is incorrect, please re-enter it ")
            print()
    # Modify students 
    def xiugai(self):
        name_xiugai=input(" Please enter the name of the student you want to modify :")


        for student_dict_1 in self.student_list:

            if name_xiugai == student_dict_1["name"]:
                print()
                print("----- Modify interface -----")
                print()
                print(" Name \t\t", " Class \t\t", " Age \t\t", " Telephone number \t\t", " Home address \t\t")
                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                                     student_dict_1["class"],
                                                     student_dict_1["age"],
                                                     student_dict_1["phone"],
                                                     student_dict_1["address"]))
                # Enter is not modified 

                student_dict_1["name"]=self.new_input(student_dict_1["name"]," Please enter the modified student name [ Enter is not modified ]:")
                student_dict_1["class"]=self.new_input(student_dict_1["class"]," Please enter the modified student class [ Enter is not modified ]:")
                student_dict_1["age"]=self.new_input(student_dict_1["age"]," Please enter the modified student age [ Enter is not modified ]:")
                student_dict_1["phone"]=self.new_input(student_dict_1["phone"]," Please enter the modified student's mobile phone number [ Enter is not modified ]:")
                student_dict_1["address"]=self.new_input(student_dict_1["address"]," Please enter the modified student's home address [ Enter is not modified ]:")
                print()
                print(" Successful modification !")
                print()
                break
        else:
            print()
            print(" The student name you entered is incorrect, please re-enter it ")
            print()

    # Find Students 
    def find(self):
        find_name=input(" Please enter the name of the student you want to find :")
        for student_dict_1 in self.student_list:

            if find_name == student_dict_1["name"]:
                print()
                print("----- Query result interface -----")
                print()
                print(" Name \t\t", " Class \t\t", " Age \t\t", " Telephone number \t\t", " Home address \t\t")
                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                                      student_dict_1["class"],
                                                      student_dict_1["age"],
                                                      student_dict_1["phone"],
                                                      student_dict_1["address"]))
            else:
                print()
                print("----- Query result interface -----")
                print()
                print(" This student information is not available ")

    # Show all student information 
    def showall(self):

        if len(self.student_list)>0:
            print()
            print("----- Show all student information -----")
            print()
            print(" Name \t\t", " Class \t\t", " Age \t\t", " Telephone number \t\t", " Home address \t\t")
            for student_dict_1 in self.student_list:

                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                                      student_dict_1["class"],
                                                      student_dict_1["age"],
                                                      student_dict_1["phone"],
                                                      student_dict_1["address"]))
        else:
            print()
            print(" No data yet! ")
            print()
    # Set the user to return the original value without inputting the content, and return the new content after inputting the content 
    def new_input(self,yuanzhi,message):
        self.input_str=input(message)

        if len(self.input_str)>0:
            return self.input_str
        else:
            return yuanzhi


    # Save data to a file 
    def save_file(self):

        f = open("student2.txt", 'w', encoding='utf-8')
        f.write(str(self.student_list))
        f.close()
        print(" Save data to student1.txt File successful! ")


    # Read data into variables 
    def read_file(self):

         if os.path.exists('student2.txt'):
            f = open('student2.txt', 'r', encoding='utf-8')
            ret = f.read()

            self.student_list=eval(ret)
            f.close()
            print(" Data read successful !")

Related articles: