Python Development Program: Course Selection System, python? 

Source: Internet
Author: User

Python Development Program: Course Selection System, python? Zookeeper
This section describes the course selection system.

Roles: schools, students, 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:

### Author Introduction: * author: lzl ### blog address: * http://www.cnblogs.com/lianzhilei/p/5813986.html### function implementation 1. create two schools in Beijing and Shanghai. create 3 courses for linux, python, and go, start for linux \ py in Beijing, and start for go in Shanghai. course inclusion, cycle, price, create course through school 4. create a class through the School, associate the class with the course, lecturer 5. when creating a student, select a school and associate the student with the class. associate the instructor role with the school. 6. provides two role interfaces: 6.1 student views. You can register students, pay tuition fees, select a class, and 6.2 instructor views. Instructors can manage their own classes, select a class in class, and view the list of class students, modify the score 6.3 Management View of managed students, create lecturers, create classes, and create courses 7. the data generated by the above operation is serialized and saved to the file through pickle (all functions are implemented)) ### Program requirements 1. currently, the database has set up information. You can directly view and add the Beijing Course: Python Lecturer: Golden Horn king class: S14 Student: I want to learn python Course: Linux Lecturer: Silver horn king class: L01 Student: I want to learn Linux in Shanghai. Course: Go Lecturer: 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, initialize the database, and only generate the names of schools in Beijing and Shanghai during initialization. database Structure main_dict storage main logical structure: {school name: {Course name 1: {"teacher": Lecturer, "grade": class}, course name 2: {"teacher": Instructor 2, "grade": Class 2 }}, school name: {Course name 3: {"teacher": Instructor 3, "grade ": class 3}, course name 4: {"teacher": Instructor 4, "grade": Class 4 }}the data types stored in the instance object database structure The correspondence between the teacher_dict storage instructor and the class is used to facilitate the system authentication of the lecturer. The structure is {INSTRUCTOR: {grade: class}. Both database files can be expanded. 4. the program implements the following strict restrictions: ① A school cannot contain courses of the same name; ② one course can only have one lecturer; ③ After the lecturer is hired, he cannot start employment, one lecturer can only teach one course (teach python, and cannot teach linux again) ④ the class can only correspond to one course, the class name can only appear once, cannot be repeated (python class s14, in a linux class, the s14 class is no longer available. ### the Extended Program does not define the student class, the class can be defined later, and the student attribute (age, score) can be added ), modify the Student Score information and add the function to the instructor center. Obviously, I have no time to complete it ..... The program separates different modules by function, which can be simpler.Readme

 

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.

} Q (c _ main _ schooscsi) q} q (X nameqX Beijing qX addrqX Beijing qub} q (c _ main _ Courseq) q} q (X priceqX 9900qhX PythonqX timeqX 7qub} q (X teacherqc _ main _ Teacherq) q} q (X roleqX instructor qX schoolqhhX Kingdom qX ageqX 33qX courseqX PythonqubX gradeqc _ main _ Gradeq) q} q! (HhX studentq "cbuiltinssetq #] q $ q % Rq & hX Pythonq 'hx S14q (ubuh) � q)} q * (hX 9000q + hX Linuxq, hX 8q-ub} q. (hh) � q/} q0 (hhhhhX qq1hx 25q2hX Linuxq3ubhh) �q4} q5 (hh1h "h #] q6 �q7rq8hx Linuxq9hX L01q: ubuuh) q ;} q <(hX Shanghai q = hX Shanghai q> ub} q? H) q @} qA (hX 8000 qBhX GoqChX 9 qDub} qE (X teacherqFh) �qg} qH (hX instructor qIhh = hX tianpeng Marshal qJhX 25 qKhX GoqLubX gradeqMh) �qn} qO (hhw." h #] qP. qQRqRhX GoqShX S01qTubusu.Main_dict} q (c _ main _ Teacherq) q} q (X roleqX instructor qX schoolqX Beijing qX nameqX Kingdom q X ageqX 33qX courseqX Pythonqub} qX gradeqc _ main _ Gradeq) q} q (X teacherqh X studentqcbuiltinssetq] qX I want to learn pythonqa qRqhX PythonqhX S14qubsh) q} q (hX instructor qhX Beijing qhX q hX 25q! HX Linuxq "ub} q # X gradeq $ h) q %} q & (hh] q'x I want to learn linuxq (a q) rq * hX Linuxq + hX L01q, ubsh) q-} q. (hX lecturer q/hX Shanghai q0hX tianpeng Marshal q1hX 25q2hX Goq3ub} q4X gradeq5h) �q6} q7 (hh1hh] q8X I want to learn go language q9a �q: Rq; hX Goq  

4. Program main. py

#! /Usr/bin/env python #-*-coding: UTF-8-*-#-Author-Lianimport 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. addr) Def hire_teacher (self, dict, course, teacher, file): # Add the instructor information to the database dict [self] [course] = {"teacher": teacher} file_oper (file, "wb", dict) def create_course (self, dict, course, file): # Add course materials to the database dict [self] [course] ={} file_detail (file, "wb", dict) def create_grade (self, dict, teacher_dict, course, grade, teacher, file1, file2 ): # database add class information dict [self] [course] ["grade"] = grade file_oper (file1, "wb", dict) teacher_dict [te Acher] = {"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. teac Her = 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 a lecturer 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: dic T = 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]. n Ame) 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_infodef 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 choicedef 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

* ******************** School center ***************** ******

 

* ******************** Student center ***************** ******

 

 

********************* Lecturer center ***************** ******

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.