Python implements the school management system and python implements the management system.
The example in this article shares the code for implementing the school management system in Python for your reference. The specific content is as follows:
I. Function Analysis
The school management system should be able to allocate the school's teachers, including students in school, study, and out-of-school students.
Ii. Program Interpretation
1. The following program implements the basic functions of the school management system, including:
1) School Enrollment
2) Recruitment of lecturers
3) Course Addition
4) and so on
2. There are also many unimplemented functions, such:
1) One of the student classes is to pay the fee, and one is to register. These two methods should be associated and can be registered only after the payment is successful.
2) each teacher should be able to view the information of his/her students in various ways, such as by name and student ID.
3) each student should be able to view all the courses and teachers in the school.
4) all such information must be stored in a file or database for permanent storage.
5) when the customer uploads the corresponding data, it should be constrained. For example, the student ID must be a 10-digit positive integer (here, to avoid an error, set all data to string type)
6) Delete, modify, and query lecturers, students, and courses.
7) various objects need to input too much information during initialization. Therefore, only the unique ID and PASSWD are required for logon.
8) and so on
Ii. program code
#! /Usr/bin/env python # coding: UTF-8 "" file: Management. pydate: 9/9/179: 57 PMauthor: hxdesc: Management System prototype "" # Add module import sysimport json # School class definition class School (object ): # initialization function def _ init _ (self, SchoolName, SchoolPlace, schoolmoname): self. schoolName = SchoolName self. schoolPlace = SchoolPlace self. schoolmou = SchoolMotto # admission function def RecruitStu (self): NewStuName = raw_input ("StuName:") NewStuAge = raw_input ("StuAge :") NewStuSex = raw_input ("StuSex:") NewStuSchool = raw_input ("StuSchool:") CourseNo = raw_input ("CourseNo:") NewStuID = raw_input ("StuID :") coursePrice = raw_input ("CoursePrice:") NewStu = Stu (NewStuName, NewStuAge, NewStuSex, NewStuSchool, CourseNo, NewStuID, CoursePrice) # instantiate the student object principal = {"StuName ": newStuName, "StuAge": NewStuAge, "StuSex": NewStuSex, "StuSchool": NewStuSchool, "CourseNo": CourseNo, "StuID ": NewStuID, "CoursePrice": CoursePrice} # store the instructor information in a dictionary. if not dic: dic [NewStuName] = stus_dict json. dump (dic, open ("student_db", "w"), encoding = 'utf-8', ensure_ascii = False, indent = 2) else: if dic. get (NewStuName): print ("% s student already exists, cannot register student with the same name" % NewStuName) else: dic [NewStuName] = stus_dict json. dump (dic, open ("student_db", "w"), encoding = 'utf-8', ensure_ascii = False, indent = 2) print ("The student has already Added successfully ". center (50, '-') NewStu. StuInfo () # hire a lecturer def HireTch (self): print" Welcome to hire teacher from here ~ "NewTeacherName = raw_input (" Please input the teacher's name: ") NewTeacherAge = raw_input (" Please input the teacher's age :") newTeacherSex = raw_input ("Please input the teacher's sex:") NewCourseNo = raw_input ("Please input the teacher's course number :") newSalary = raw_input ("Please input the teacher's salary:") NewTeacher = Teacher (NewTeacherName, NewTeacherAge, NewTeacherSex, NewCourseNo, NewSal Ary) # instantiate teachers_dict = {"TeacherName": NewTeacherName, "TeacherAge": NewTeacherAge, "TeacherSex": NewTeacherSex, "CourseNo": NewCourseNo, "Salary ": newSalary} # store lecturer information in the dictionary # deserialize the lecturer's dictionary to the dic dictionary using json if not dic: # If the dictionary is empty, dic [NewTeacherName] = teachers_dict # associate the lecturer's name with the lecturer's object # serialize the lecturer's dictionary to json in the teacher_db file through json. dump (dic, open ("teacher_db", "w"), encoding = 'utf-8', ensure_ascii = False, indent = 2) else: # If a lecturer already exists in the file Information if dic. get (NewTeacherName): # If no key exists in the dictionary, none is returned. No error is reported for print ("% s lecturer already exists, cannot create lecturer with the same name" % NewTeacherName) else: dic [NewTeacherName] = teachers_dict json. dump (dic, open ("teacher_db", "w"), encoding = 'utf-8', ensure_ascii = False, indent = 2) NewTeacher. teacherInfo () # print new instructor information on the screen # Add course def CreateCourse (self): print "Welcome to create course! "Outputs = raw_input (" CourseNo: ") NewCourseName = raw_input (" CourseName: ") NewCoursePrice = raw_input (" CoursePrice: ") NewCourse = Course (NewCourseNo, NewCourseName, NewCoursePrice) # The newly created object is directly instantiated courses_dict = {"CourseNo": NewCourseNo, "CourseName": NewCourseName, "CoursePrice": NewCoursePrice} # The lecturer information is stored in the dictionary if not dic: dic [NewCourseNo] = courses_dict json. dump (dic, open ("course_db", "w"), encoding = 'U Tf-8 ', ensure_ascii = False, indent = 2) else: if dic. get (NewCourseNo): print ("% s course already exists, cannot register course with the same course number" % NewCourseNo) else: dic [NewCourseNo] = courses_dict json. dump (dic, open ("course_db", "w"), encoding = 'utf-8', ensure_ascii = False, indent = 2) print ("Course has already created successfully ". center (50, '-') print ("" CourseNo: % s CourseName: % s CoursePrice: % s "" % (NewCourseNo, NewCourseName, NewCoursePrice) c Lass Teacher (object): def _ init _ (self, TeacherName, TeacherAge, TeacherSex, CourseNo, Salary): self. teacherName = TeacherName self. teacherAge = TeacherAge self. teacherSex = TeacherSex self. courseNo = CourseNo self. salary = Salary def TeachKnowledge (self): print "Teach Knowlege ~ "Def TeacherInfo (self): print (" "------------- instructor information ------------- Name: % s Age: % s Sex: % s CourseNo: % s Salary: % s "% (self. teacherName, self. teacherAge, self. teacherSex, self. courseNo, self. salary) # Course class definition class Course (object): def _ init _ (self, CourseNo, CourseName, CoursePrice): self. courseNo = CourseNo self. courseName = CourseName self. coursePrice = CoursePrice def ShowCourseInfo (self): print ("" Co UrseNO: % s CourseName: % s CoursePrice: % s "" % (self. courseNo, self. courseName, self. coursePrice) # student class definition class Stu (object): def _ init _ (self, StuName, StuAge, StuSex, StuSchool, CourseNo, StuID, CoursePrice): self. stuName = StuName self. stuAge = StuAge self. stuSex = StuSex self. stuSchool = StuSchool self. courseNo = CourseNo self. stuID = StuID self. coursePrice = CoursePrice def Study (self): print "study" def P AyMoney (self): print "Paying for money ~ "Def StuInfo (self): print (" "--------------- student information -------------- Name: % s Age: % s Sex: % s School: % s CourseNo: % s ID: % s CoursePrice: % s "" % (self. stuName, self. stuAge, self. stuSex, self. stuSchool, self. courseNo, self. stuID, self. coursePrice) def students_view (): # student view while True: pro = "1. welcome to registration 2. 3. to exit, select "num = raw_input (pro) if num = '1': choice_school_obj.RecruitStu () # Call the student registration method and generate the student object elif num = '2': break elif num = '3': sys. exit () else: continuedef teacher_view (): # instructor view name = raw_input ("Enter the instructor name:") while True: if dic. get (name) or teachers_dict.get (name): print ("Welcome % s instructor ". center (50, '-') % name) elif not dic. get (name) and not teachers_dict.get (name): print ("% s "% name) break pro = "1. view Student Information 2. 3. to exit, enter your selection: "num = raw_input (pro) if num = '1': if teachers_dict.get (name): teachers_dict [name]. show_student () # view student information else: print ("function not complete, only lvah, cheng") elif num = '2': break elif num = '3 ': sys. exit () else: continuedef school_view (): # School view while True: pro = "" 1. create course 2. enrollment 3. hire lecturers 4. 5. to exit, enter your selection: "num = raw_input (pro) if num = '1': choice_school_obj.CreateCourse () elif num = '2': choice_school_obj.RecruitStu () elif num = '3': choice_school_obj.HireTch () elif num = '4': break elif num = '5': sys. exit () else: continuedef main (): global dic # global variable global choice_school_obj dic ={} while True: print ("select school ". center (50, '*') pro1 = "" 1.% s 2.% s 3. 4. to exit, enter your selection: "" % (school1.SchoolName, school2.SchoolName) choice_school = raw_input (pro1) if choice_school = '1 ': criteria = school1 # pass the object reference to choice_school elif choice_school = '2': choice_school_obj = school2 elif choice_school = '3': break elif choice_school = '4': sys. exit () else: continue while True: print ("select View ". center (50, '*') pro2 = "" 1. student View 2. instructor view 3. school Management View 4. 5. to exit, select View: "" num = raw_input (pro2) if num = '1': print ("Welcome to Student View ". center (50, '*') students_view () elif num = '2': print ("welcome to the instructor View ". center (50, '*') teacher_view () elif num = '3': print ("Welcome to School Management View ". center (50, '*') school_view () elif num = '4': break elif num = '5': sys. exit () else: continueif _ name _ = '_ main __': teachers_dict ={} courses_dict ={} stus_dict ={} school1 = School ("university A", "Qujiang campus", "Motherland, honor, responsibility ") # instantiate two schools school2 = School ("B ", "Chang 'an district", "Patriotic, qiushi, and forging ahead") t1 = Teacher ("leo", "28 ", "male", "01", "10000") t2 = Teacher ("harry", "26", "female", "02", "9000 ") # instantiate two lecturers, teachers_dict ["leo"] = t1 teachers_dict ["harry"] = t2 teacher_dict = {"TeacherName": "leo", "TeacherAge": "28 ", "TeacherSex": "male", "CourseNo": "01", "Salary": "10000"} teacher_dict = {"TeacherName": "harry", "TeacherAge ": "26", "TeacherSex": "female", "CourseNo": "02", "Salary": "9000"} course1 = Course ("01 ", "Linux cloud automated O & M", "12800") # instantiate two courses course2 = Course ("02", "c/c ++ Development", "9800 ") courses_dict ["01"] = course1 courses_dict ["02"] = course2 courses_dict = {"CourseNo": "01", "CourseName": "Linux cloud automated O & M ", "CoursePrice": "12800"} courses_dict = {"CourseNo": "02", "CourseName": "c/c ++ Development", "CoursePrice ": "9800"} stu1 = Stu ("Katy", "18", "female", "A Emy", "01", "3150911026", "12800 ") # instantiate two students stu2 = Stu ("Betty", "18", "male", "B ", "02", "3150911022", "12000 ") stus_dict ["Katy"] = stu1 stus_dict ["Betty"] = stu2 stu_dict = {"StuName": "Katy", "StuAge": "18", "StuSex ": "female", "StuSchool": "university A", "CourseNo": "01", "StuID": "3150911026", "CoursePrice ": "12800"} stu_dict = {"StuName": "Betty", "StuAge": "18", "StuSex": "male", "StuSchool": "B ", "CourseNo": "02", "StuID": "3150911022", "CoursePrice": "12000"} print (school1, school2) main ()
Iii. Running results
The implementation of basic functions is not one by one. After the preliminary functions are completed, they will be uploaded.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.