Python Course Selection System development Program _python

Source: Internet
Author: User
Tags serialization

This program for the Python selection system for the development, for everyone to refer to, the specific content as follows

role: School, student, course, lecturer
Requirements:
1. Create 2 schools in Beijing and Shanghai
2. Create Linux, Python, go 3 courses, linux\py in Beijing, go in Shanghai Open
3. Courses include, cycle, price, curriculum creation through the school
4. Create classes through schools, class-related courses, lecturers
5. When creating students, select school, associate class
5. Associate schools when creating instructor roles,
6. Provide two role interfaces
7. Student view, can register, pay tuition, select class,
8. Instructor view, the instructor can manage their own classes, select classes in class, view the class list of students, modify the management of the student's performance
9. Manage views, create lecturers, create classes, create courses
10. The data generated by the above operation is stored in the file through pickle serialization.

Program:

1, the most important readme:

### authors introduce:
* Author:lzl
### Blog Address:
* http://www.cnblogs.com/lianzhilei/p/5813986.html

### function implementation
1. Create 2 schools in Beijing and Shanghai
2. Create Linux, Python, go 3 courses, linux\py in Beijing, go in Shanghai Open
3. Courses include, cycle, price, curriculum creation through the school
4. Create classes through schools, class-related courses, lecturers
5. When creating students, select school, associate class
5. Associate schools when creating instructor roles,
6. Provide two role interfaces
6.1 Student view, can register, pay tuition, select class,
6.2 Instructor View, the instructor can manage their own class, choose the class in class, view the class student list, revise the management of the students ' results
6.3 Managing views, creating lecturers, creating classes, creating courses
7. The data generated by the above operation is stored in the file through pickle serialization.
(all features are implemented)

# # #程序需知
1. The current database is well established and can be viewed directly to increase
Beijing Course: Python Lecturer: King Horn Class: S14 Students: I want to learn Python
Course: Linux lecturer: Silver Kok King class: L01 Students: I want to learn Linux
Shanghai Course: Go Lecturer: Field Marshal class: G01 student: I'm going to learn
2. The database can also be deleted under the two files, data, execution procedures, database initialization, initialization only to generate Beijing, Shanghai school name
3. Database structure MAIN_DICT Storage of the main logical structure:
{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 instance objects
Database structure Teacher_dict storage instructor and class correspondence, used to facilitate the instructor login system certification, the structure of
{lecturer: {Grade: Class}
Two database files can be extended
4. The procedure implements the following stringent restrictions:
① A school can't have a class with the same name.
② A course can only have one lecturer
③ Instructor is hired, no longer hired, a lecturer can only teach a course (teaching python, you can no longer teach Linux)
④ class can only correspond to one course, class name can only appear once, can not be repeated (Python class S14,linux class can not appear S14 Class)

# # #后期扩展
The program does not define student classes, later definable classes, add student attributes (age, grade), can modify the student performance information, add the function to the teacher center, it is obvious
I don't have time for this.
Program to separate modules by function, can be more concise

2, the program directory structure:

3. Database:

Main_dict and teacher_dict Two database files are not created, run programs automatically generate

4, program main.py

#!/usr/bin/env python #-*-coding:utf-8-*-#-author-lian import Pickle,os base_dir = Os.path.dirname (Os.path.dirname ( Os.path.abspath (__file__)) #数据地址 __db_main = Base_dir + R "\database\main_dict" __db_teacher = Base_dir + R "\database\tea Cher_dict "Class School (object): #创建学校 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): # Database Add Instructor Info Dict[self][course] = {"Teacher": Teacher} file_oper (file, WB, dict) def create_course (self,dict,course,file ): # Database Add course Information dict[self][course]={} file_oper (file, WB, dict) def create_grade (Self,dict,teacher_dict,course,grade, Teacher,file1,file2): #数据库添加班级信息 dict[self][course]["grade"] = Grade File_oper (file1, "WB", Dict) Teacher_dict[teacher ] = {"Grade": Grade} file_oper (File2, WB, Teacher_dict) class Course (): #创建课程 def __init__ (self,name,price,time): SE Lf.name = Name Self.price =Price Self.time = Time def cat_course (self): #查看课程信息 print ("Course:%s": "¥%s" \ T cycle: "%s months"% (Self.name,self.price,sel F.time) class Grade (): # Create Class Def __init__ (self,name,course,teacher): Student = set ([]) Self.name = name Self.cours E = Course Self.teacher = Teacher Self.student = Student def cat_grade (self): #查看班级信息 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 = Age class Teacher (People): # Create Instructor def __init__ (self,name,age,school,course,role= "lecturer"): Super (Teacher,self). __init__ (name,age) self.role = role Self.school = School Self.course = Course def cat_teacher (sel  f): #查看老师资料和课程 print (' course '%s ' \ \ t instructor '%s '% (self.course,self.name)) def file_oper (File,mode,*args): #数据库写入, read operation 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:dict = pic Kle.loads (F.read ()) Return dict def information (Dict,mode,*args): ' Print the corresponding output information ' by matching mode mode ' if Args:dict_info, se T_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: #key值不是字符串 dict_info[key. Name] = key return Dict_info,set_info def school_center (): #学校管理中心 Flag = True while flag:dict_main = File_op ER (__db_main, "RB") #主字典 res_dict = information (Dict_main, "main") [0] #打印学校信息 school_name = input ("\33[34;0m Enter the name of the school you want to select \33 [0m: "). Strip () if School_Name in Res_dict:school = Res_dict[school_name] #匹配选择的学校 while Flag:print ("\33[32;1m Welcome to the" school \33[0m "%s". Center (50, "*")%school.name choice = options (List_school) #打印当前选项 if choice = = "1": While True:print ("\33[32;0m School"%s "is currently Some class information \33[0m ". Center (+,"-")%school.name) teacher_dict = File_oper (__db_teacher," RB ") Res_course = information (dict _main[school], "None") [0] Set_info = set ([]) if Res_course: # Print Course and instructor correspondence for I in res_course:k = Res_cours E[i] Res_grade = information (Dict_main[school][k], "grade", Set_info) [1] If_cont = input ("\n\33[34;0m whether to create class" Y "create" B "Exit \33[0m:") if If_cont = = "Y": Grade_name = Input ("\33[34;0m Enter the name of the class to be created \33[0m:"). Strip () Course_name = input (" \33[34;0m input to the class to be on the course \33[0m: "). Strip () if course_name in res_course:course = Res_course[course_name] If Dict_ma In[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_TEAC 

    Her) else:print ("\33[31;0m Error: Current class already exists \33[0m") else:print ("\33[31;0m Error: Current course not lecturer \33[0m") Else: Print ("\33[31;0m Error: Course"%s "does not exist, please create course \33[0m"% course_name) if If_cont = = "B": break If Choice = "2": # Recruitment lecturer while True:print ("\33[32;0m School"%s "currently has courses and lecturers \33[0m". Center (+, "-")%school.name) Res_course = information (d Ict_main[school], "None") [0] Set_info = set ([]) if res_course: #打印课程与讲师对应关系 for i in res_course:k = Res_co Urse[i] Res_teacher = information (Dict_main[school][k], "Teacher", Set_info) [1] If not res_teacher:print (course)  %s "no instructor" "% (i)) If_cont = input (" \n\33[34;0m recruit lecturer "Y" recruitment "B" Exit \33[0m: ") if If_cont = =" Y ": Teacher_name =  Input ("\33[34;0m Enter the name of the instructor to be recruited \33[0m:"). Strip () Teacher_age = input ("\33[34;0m enter the age of the instructor to be recruited \33[0m:"). Strip () Course_name = input ("\33[34;0m input Instructor"%s "courses to be taught \33[0m:"%teacher_name. Strip () if course_name in Res_course:course = Res_course[course_name] #创建讲师并写入数据 Library if teacher_name not in Res_teacher:teacher = Teacher (teacher_name,teacher_age,school.name,course_name) s Chool.hire_teacher (Dict_main, course, teacher, __db_main) else:print ("\33[31;0m Error: Teacher"%s "has been hired \33[0m"%teacher_n  AME) Else:print ("\33[31;0m Error: Course '%s" does not exist, please first create course \33[0m "%course_name" If If_cont = "B": break if choice = = "3": #创建课程 while True:print ("\33[32;0m School"%s "current course \33[0m". Center ("-")%school.name) res_dict = Informati On (Dict_main[school], "course") [0] #打印课程信息赋值给字典course_dict If_cont = input ("\n\33[34;0m to create Course" Y "to create" B "exit \33[0m:") I F If_cont = = "Y": Course_name = Input ("\33[34;0m Enter the course to be created \33[0m:"). Strip () if Course_name not in res_dict: #课程不存在, Chuang  Build Price = input ("\33[34;0m Input Course"%s "\33[0m:"% (course_name)) time = input ("\33[34;0m Enter course '%s ' cycle (month) \33[0m:"%
    (Course_name)) CourSE = Course (course_name, Price, time) #创建课程course School.create_course (Dict_main,course, __db_main) #关联学校和课程 else:  #课程存在 Print ("\33[31;0m Error: Current Course"%s "already exists \33[0m"% (course_name)) if If_cont = = "B": break If Choice =

 "4": Flag = False if Flag:print ("\33[31;0m Error: Entered school"%s "does not exist \33[0m"% (school_name)) def teacher_center (): #讲师中心 Print ("\33[32;1m Welcome to the lecturer Center \33[0m". Center (+, "*")) Teacher_dict = File_oper (__db_teacher, "RB") Dict_info = information ( Teacher_dict, "Teacher_center") [0] #验证登录 teacher_name = input ("\n\33[34;0m Enter the name of the instructor to log in \33[0m:"). Strip () if Teacher_name In Dict_info:while true:print ("\33[32;1m Welcome to the Management center of the instructor"%s "\33[0m". Center (+, "*")%teacher_name) Choice = options (list _teacher) teacher = Dict_info[teacher_name] Grade = teacher_dict[teacher]["Grade"] If choice = "1": Print ("\33[3 2;0m Lecturer "%s" Class information \33[0m ". Center ("-")%teacher.name) print (" school "%s" \ T course "%s" \ T class "%s" \ T)% (Teacher.school, Teacher.course,grade.name)) any = input ("\n\33[34;0m enter any key to exit the current \33[0m: "") if choice = = "2": Print ("\33[32;0m Instructor"%s "Class student list \33[0m". Center ("-")% Teacher.name)
   Print ("class"%s "\ n Student"%s "% (grade.name,grade.student)) any = input (" \n\33[34;0m Enter any key exit current \33[0m: ") if choice = =" 3 ": Break Else:print ("\33[31;0m Error: Instructor"%s "does not exist \33[0m"% (teacher_name)) def student_center (): #学员中心 print ("\33[32;1m Welcome to the trainees" Heart Center \33[0m ". Center (" * ")) while True:choice = Options (list_student) #打印学生中心选项 if choice = =" 1 ": Student_name = In Put ("\33[34;0m Enter the name of the trainee \33[0m:") dict = File_oper (__db_main, "RB") Teacher_dict = File_oper (__db_teacher, "RB") School_ Dict = information (Dict, "main") [0] #打印当前可选的学校 school_name = input ("\33[34;0m Enter the name of the school to choose \33[0m:"). Strip () if School_name In School_dict:school = School_dict[school_name] If Dict[school]: course_dict = information (Dict[school), "course") [0] # Print the current school curriculum course_name = input ("\33[34;0m Enter the course you want to select \33[0m:"). 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 Grade = teacher_dict[teacher]["Grade"] Print ("%s"% (course.name,course.price)) If_pay = input ("\33[34; 0m whether pay the current fee "Y" \33[0m: ") if If_pay = =" Y ": #上面全部匹配成功, successful course grade.add_student (student_name,teacher_dict,teacher,__ Db_teacher) Print ("\33[31;0m selected successfully \33[0m") any = input ("\n\33[34;0m enter any key to exit current \33[0m:") else:print ("\33[31;0m wrong  Error: Course no class \33[0m ") else:print (" \33[31;0m Error: Course does not exist \33[0m ") Else:print (" \33[31;0m Error: Current School No course \33[0m ") If choice = = "2": Break def Options (list): #打印可选择的操作模式, and return the selected value for I, v. in Enumerate (list): print (i+1, v) choice = input ("\33[34 0m Select to enter mode \33[0m: ") return choice def start ():" The program Begins "while True:print (" \33[35;1m Welcome to the elective system \33[0m ". Center (50," # " ) Choice = options (List_main) #打印选项 If choice = "1": Student_center () #学生中心 If choice = "2": Teacher_center () #教
 Division Center If Choice = = "3": School_center () #学校中心 if choice = = "4": Break Def init_database (): ' Database initialization, no existence is created, existence skipped ' BJ = School ("Beijing", "Peking City")  SH = School ("Shanghai", "Shanghai City") if not os.path.exists (__db_teacher): Dict = {bj:{},sh:{}} file_oper (__db_main, "WB", Dict) if Not os.path.exists (__db_teacher): Dict = {} file_oper (__db_teacher, "WB", dict) if __name__ = ' __main__ ': Init_databas E () #初始化数据库 list_main = ["Student Center", "Lecturer Center", "School Center", "exit"] List_school = ["Create Class", "Recruit Lecturer", "Create Course", "return"] List_teacher = ["View class

 "," View class student List "," return "] list_student = [" Student Registration "," return "] Start ()

5, the process of the operation of the brief diagram

Student Center ***********************

Lecturer Center ***********************

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.