Python Course Selection System Development Program and python Course Selection System Development
This program is developed for the Python Course Selection System for your reference. The specific content is as follows:
Role:Schools, trainees, courses, Lecturers
Requirements:
1. Create two schools in Beijing and Shanghai
2. Create three courses for linux, python, and go. linux \ py is available in Beijing, and go is available in Shanghai.
3. Course inclusion, cycle, price, create course through school
4. Create a class through the school, and associate the relevant courses and lecturers in the class
5. When creating a student, select a school and associate the student with a class.
5. Associate the instructor role with the school,
6. Two Role interfaces are provided.
7. In the student view, you can register students, pay tuition fees, and select a class,
8. In the instructor view, the lecturer can manage his class, select a class in class, view the list of class students, and modify the score of the managed students.
9. Manage the view, create a lecturer, create a class, and create a course
10. The data produced by the above operations are serialized and saved to the file through pickle.
Program:
1. The most important readme:
### Introduction:
* Author: lzl
### Blog address:
* Http://www.cnblogs.com/lianzhilei/p/5813986.html
### Function implementation
1. Create two schools in Beijing and Shanghai
2. Create three courses for linux, python, and go. linux \ py is available in Beijing, and go is available in Shanghai.
3. Course inclusion, cycle, price, create course through school
4. Create a class through the school, and associate the relevant courses and lecturers in the class
5. When creating a student, select a school and associate the student with a class.
5. Associate the instructor role with the school,
6. Two Role interfaces are provided.
6.1 student view, you can register, pay tuition, select a class,
6.2 In the instructor view, the lecturer can manage his/her own class, select a class in class, view the list of class students, and modify the score of the managed students.
6.3 Management View, creating lecturers, creating classes, and creating courses
7. The data generated by the above operations are serialized and saved to the file through pickle.
(All functions are implemented)
### Program Requirements
1. You can view and add the information already created in the current database.
Beijing Course: Python Lecturer: Kingdom Class: S14 Student: I want to learn python
Course: Linux Lecturer: class: L01 Student: I want to learn Linux
Shanghai Course: Go INSTRUCTOR: Grand Marshal class: G01 Student: I want to learn GO
2. You can also delete the two database files in the database, clear the data, execute the program, and initialize the database. during initialization, only the names of schools in Beijing and Shanghai are generated.
3. database structure the main logical structure of main_dict storage:
{School name: {Course name 1: {"teacher": Lecturer, "grade": class}, course name 2: {"teacher": Lecturer 2, "grade ": class 2 }},
School Name: {Course name 3: {"teacher": Lecturer 3, "grade": Class 3}, course name 4: {"teacher": Lecturer 4, "grade ": class 4 }}}
The stored data types are all instance objects.
Database structure: the correspondence between the teacher_dict storage instructor and the class, used to facilitate the login system authentication of the lecturer. The structure is
{INSTRUCTOR: {grade: class}
Both database files can be extended
4. The program implements the following strict restrictions:
① A course of the same name cannot appear in a school
② One course can only have one lecturer
③ After a lecturer is hired, he cannot be hired any more. One lecturer can only teach one course (no more than linux if he teaches python)
④ The class can only correspond to one course. The class name can only appear once and cannot be repeated (for python class s14, the class s14 in linux cannot appear again)
### Post-Extension
The program does not define the student class. In the later stage, you can define the class, add the student attributes (age, score), modify the Student Score information, and add the function to the instructor center. Obviously
I have no time .....
The program separates different modules by function, which can be simpler.
2. Program directory structure:
3. database:
The main_dict and teacher_dict database files cannot be created, and are automatically generated by running the program.
4. Program main. py
#! /Usr/bin/env python #-*-coding: UTF-8-*-#-Author-Lian import pickle, osBASE_DIR = OS. path. dirname (OS. path. dirname (OS. path. abspath (_ file __))) # data address _ db_main = BASE_DIR + r "\ database \ main_dict" _ db_teacher = BASE_DIR + r "\ database \ teacher_dict" class School (object ): # create school def _ init _ (self, name, addr): self. name = name self. addr = addr def cat_school (self): print ("school name: [% s] \ t address: [% s]" % (self. name, self. ad Dr) def hire_teacher (self, dict, course, teacher, file): # Add instructor information to the database dict [self] [course] = {"teacher ": teacher} file_course (file, "wb", dict) def create_course (self, dict, course, file ): # database course materials dict [self] [course] ={} file_grade (file, "wb", dict) def create_grade (self, dict, teacher_dict, course, grade, teacher, file1, file2): # add class information to the database dict [self] [course] ["grade"] = grade file_1_( file1, "wb", dict) teacher_dict [Teacher] = {"grade": grade} file_train (file2, "wb", teacher_dict) class Course (): # create Course def _ init _ (self, name, price, time): self. name = name self. price = price self. time = time def cat_course (self): # view course information print ("Course: [% s] \ t price: [¥ % s] \ t cycle: [% s month] "% (self. name, self. price, self. time) class Grade (): # create a class def _ init _ (self, name, course, teacher): student = set ([]) self. name = name self. course = course self. te Acher = teacher self. student = student def cat_grade (self): # view the class information print ("Class: [% s] \ t Course: [% s] \ t Lecturer: [% s] "% (self. name, self. course, self. teacher) def add_student (self, student_name, dict, teacher, file): self. student. add (student_name) dict [teacher] = {"grade": self} file_oper (file, "wb", dict) class People (): def _ init _ (self, name, age): self. name = name self. age = ageclass Teacher (People): # create instructor def _ init _ (Self, name, age, school, course, role = ""): super (Teacher, self ). _ init _ (name, age) self. role = role self. school = school self. course = course def cat_teacher (self): # view instructor information and course print ('course [% s] \ t instructor [% s] '% (self. course, self. name) def file_oper (file, mode, * args): # if mode = "wb": with open (file, mode) as f: dict = args [0] f. write (pickle. dumps (dict) if mode = "rb": with open (file, mode) as f: d Ict = pickle. loads (f. read () return dictdef information (dict, mode, * args): ''' print the output information ''' if args: dict_info by matching the mode, set_info = {}, args [0] else: dict_info, set_info = {}, set ([]) if dict: for key in dict: if mode = "course ": key. cat_course () if mode = "main": key. cat_school () if mode = "teacher" and key = "teacher": dict [key]. cat_teacher () # dict_info [key] = dict [key] set_info.add (dict [key]. Name) if mode = "grade" and key = "grade": dict [key]. cat_grade () set_info.add (dict [key]. name) if mode = "teacher_center": pass if type (key )! = Str: # the key value is not the string dict_info [key. name] = key return dict_info, set_info def school_center (): # School Management Center Flag = True while Flag: dict_main = file_oper (_ db_main, "rb ") # main dictionary res_dict = information (dict_main, "main") [0] # print School information school_name = input ("\ 33 [34; 0 m enter the name of the school to be selected \ 33 [0 m :"). strip () if school_name in res_dict: school = res_dict [school_name] # match the selected school while Flag: print ("\ 33 [32; 1 m welcome to [% s] School \ 33 [0 m ". center (50, "*") % school. name) choice = options (list_school) # print the current option if choice = "1": while True: print ("\ 33 [32; 0 m school [% s] current class information \ 33 [0 m ". center (40, "-") % school. name) teacher_dict = file_course (_ db_teacher, "rb") res_course = information (dict_main [school], "None") [0] set_info = set ([]) if res_course: # print the correspondence between the course and the lecturer. for I in res_course: k = res_course [I] res_grade = information (dict_main [school] [k], "grade", set_info) [1] if_cont = input ("\ n \ 33 [34; 0 m whether to create class [y] Create [B] exit \ 33 [0 m :") if if_cont = "y": grade_name = input ("\ 33 [34; 0m enter the name of the class to be created \ 33 [0 m :"). strip () course_name = input ("\ 33 [34; 0 m enter the course to be attended by the class \ 33 [0 m :"). strip () if course_name in res_course: course = res_course [course_name] if dict_main [school] [course]: teacher = dict_main [school] [course] ["teacher"] if grade_name not in res_grade: grade = Grade (grade_name, course_name, teacher. name) school. create_grade (dict_main, teacher_dict, course, grade, teacher, _ db_main, _ db_teacher) else: print ("\ 33 [31; 0 m error: the current class already has \ 33 [0 m ") else: print (" \ 33 [31; 0m error: No lecturer in the current course \ 33 [0 m ") else: print ("\ 33 [31; 0 m error: course [% s] does not exist. Please create course \ 33 [0 m" % course_name) if if_cont = "B ": break if choice = "2": # recruiting lecturer while True: print ("\ 33 [32; 0m school [% s] existing courses and lecturers \ 33 [0 m ". center (40, "-") % school. name) res_course = information (dict_main [school], "None") [0] set_info = set ([]) if res_course: # print the correspondence between the course and the instructor for I in res_course: k = res_course [I] res_teacher = information (dict_main [school] [k], "teacher", set_info) [1] if not res_teacher: print ("course [% s] \ t instructor [None]" % (I) if_cont = input ("\ n \ 33 [34; 0 m whether to hire a lecturer [y] recruit [B] Quit \ 33 [0 m: ") if if_cont =" y ": teacher_name = input (" \ 33 [34; 0 m enter the name of the instructor to be hired \ 33 [0 m :"). strip () teacher_age = input ("\ 33 [34; 0 m enter the age of the instructor to be hired \ 33 [0 m :"). strip () course_name = input ("\ 33 [34; 0m input instructor [% s] course to be taught \ 33 [0 m:" % teacher_name ). strip () if course_name in res_course: course = res_course [course_name] # create a lecturer and write it into the database if teacher_name not in res_teacher: teacher = Teacher (teacher_name, teacher_age, school. name, course_name) school. hire_teacher (dict_main, course, teacher, _ db_main) else: print ("\ 33 [31; 0 m error: instructor [% s] hired \ 33 [0 m "% teacher_name) else: print (" \ 33 [31; 0 m error: course [% s] does not exist, create a course \ 33 [0 m "% course_name) if if_cont =" B ": break if choice =" 3 ": # create a course while True: print ("\ 33 [32; 0 m school [% s] existing courses \ 33 [0 m ". center (40, "-") % school. name) res_dict = information (dict_main [school], "course") [0] # print the course information and assign it to the dictionary course_dict if_cont = input ("\ n \ 33 [34; 0 m whether to create course [y] Create [B] exit \ 33 [0 m: ") if if_cont =" y ": course_name = input (" \ 33 [34; 0 m enter the course \ 33 [0 m: ") to be created :"). strip () if course_name not in res_dict: # The course does not exist. Create price = input ("\ 33 [34; 0 m enter the price of the course [% s] \ 33 [0 m: "% (course_name) time = input (" \ 33 [34; 0m input course [% s] cycle (month) \ 33 [0 m: "% (course_name )) course = Course (course_name, price, time) # create course school. create_course (dict_main, course, _ db_main) # associated schools and courses else: # the course has a print ("\ 33 [31; 0 m error: the current course [% s] already exists \ 33 [0 m "% (course_name) if if_cont =" B ": break if choice =" 4 ": flag = False if Flag: print ("\ 33 [31; 0 m error: the entered school [% s] does not exist \ 33 [0 m" % (school_name) def teacher_center (): # instructor center print ("\ 33 [32; 1 m welcome to instructor center \ 33 [0 m ". center (50, "*") teacher_dict = file_ict (_ db_teacher, "rb") dict_info = information (teacher_dict, "teacher_center ") [0] # verify the login teacher_name = input ("\ n \ 33 [34; 0 m enter the name of the lecturer to log on \ 33 [0 m :"). strip () if teacher_name in dict_info: while True: print ("\ 33 [32; 1 m welcome to the Management Center of the lecturer [% s] \ 33 [0 m ". center (40, "*") % teacher_name) choice = options (list_teacher) teacher = dict_info [teacher_name] grade = teacher_dict [teacher] ["grade"] if choice = "1": print ("\ 33 [32; class information of 0 m instructor [% s] \ 33 [0 m ". center (40, "-") % teacher. name) print ("school [% s] \ t course [% s] \ t class [% s] \ t" % (teacher. school, teacher. course, grade. name) any = input ("\ n \ 33 [34; 0 m enter any key to exit the current \ 33 [0 m:") if choice = "2 ": print ("\ 33 [32; 0 m instructor list of class students in [% s] \ 33 [0 m ". center (40, "-") % teacher. name) print ("class [% s] \ n student [% s]" % (grade. name, grade. student) any = input ("\ n \ 33 [34; 0 m enter any key to exit the current \ 33 [0 m:") if choice = "3": break else: print ("\ 33 [31; 0 m error: Lecturer [% s] does not exist \ 33 [0 m" % (teacher_name) def student_center (): # student center print ("\ 33 [32; 1 m welcome to the student center \ 33 [0 m ". center (50, "*") while True: choice = options (list_student) # print student center option if choice = "1 ": student_name = input ("\ 33 [34; 0 m input Student name \ 33 [0 m:") dict = file_detail (_ db_main, "rb ") teacher_dict = file_oper (_ db_teacher, "rb") school_dict = information (dict, "main ") [0] # print the currently available school school_name = input ("\ 33 [34; 0 m input name \ 33 [0 m :"). strip () if school_name in school_dict: school = school_dict [school_name] if dict [school]: course_dict = information (dict [school], "course ") [0] # print the course course_name = input ("\ 33 [34; 0 m enter the course to be selected \ 33 [0 m:") under the current school :"). strip () if course_name in course_dict: course = course_dict [course_name] if dict [school] [course]. get ("grade"): for I in teacher_dict: if course. name = I. course: teacher = I grade = teacher_dict [teacher] ["grade"] print ("course [% s] fee is [% s]" % (course. name, course. price) if_pay = input ("\ 33 [34; 0 m whether to pay the current fee to pay [y] \ 33 [0 m:") if if_pay = "y ": # All of the above matches are successful, and the course selection is successful grade. add_student (student_name, teacher_dict, teacher ,__ db_teacher) print ("\ 33 [31; 0 m selected successfully \ 33 [0 m ") any = input ("\ n \ 33 [34; 0 m input any key to exit the current \ 33 [0 m:") else: print ("\ 33 [31; 0 m error: course does not have class \ 33 [0 m ") else: print (" \ 33 [31; 0m error: course does not exist \ 33 [0 m ") else: print ("\ 33 [31; 0 m error: no course in the current school \ 33 [0 m") if choice = "2": breakdef options (list ): # print the selectable operation mode and return the selected values for I, v in enumerate (list): print (I + 1, v) choice = input ("\ 33 [34; 0 m select to enter the mode \ 33 [0 m: ") return choice def start (): ''' program start ''' while True: print (" \ 33 [35; 1 MB Welcome To The Course Selection System \ 33 [0 m ". center (50, "#") choice = options (list_main) # print option if choice = "1": student_center () # student center if choice = "2 ": teacher_center () # instructor center if choice = "3": school_center () # School center if choice = "4": breakdef init_database (): ''' database initialization, if it does not exist, it is created. if not OS, the '''bj = School ("Beijing", "Beijing") sh = School ("Shanghai", "Shanghai") is skipped. path. exists (_ db_teacher): dict = {bj :{}, sh :{}} file_partition (_ db_main, "wb", dict) if not OS. path. exists (_ db_teacher): dict = {} file_oper (_ db_teacher, "wb", dict) if _ name _ = '_ main __': init_database () # initialize the database list_main = ["student center", "instructor center", "school center", "exit"] list_school = ["create class ", "recruiting lecturers", "creating courses", "back"] list_teacher = ["viewing classes", "viewing the list of class students ", "Return"] list_student = ["student registration", "Return"] start ()
5. A brief diagram of the program running process
* ******************** Student center ***************** ******
********************* Lecturer center ***************** ******
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.