角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
6. 创建讲师角色时要关联学校,
7. 提供两个角色接口
7.1 学员视图, 可以注册, 交学费, 选择班级,
7.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
7.3 管理视图,创建讲师, 创建班级,创建课程
8. 上面的操作产生的数据都通过pickle序列化保存到文件里
#启动类 # Author:zylong """ schoole 启动类 """ import os,sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(BASE_DIR) import core core.main.run()
入口类:main
# Author:zylong from core import homework from core import admin # from core import teacher # from core import student choose1 = { "admin":1, "teacher":2, "student":3 } def run(): # print("run") for i in choose1: print(i,choose1[i]) youchoose = int(input("选择用户")) if youchoose == 1: admin.run() # elif youchoose == 2: # teacher.run() # elif youchoose == 3: # student.run()
管理员类:
#创建班级,创建课程 # python = Course("python",30,13000) # linux = Course("linux",40,14000) # go = Course("go",50,15000) # curses = { # "python":python, # "linux":linux, # "go":go # } from core import homework from core import common adminchoose = { "创建班级":1,#这里简化,创建班级的时候,必须得有课程,要不不让创建 "创建课程":2,#课程不能单独存在,必须依存班级 "创建讲师":3, } # courselist = list() def run(): while True: schoole = common.getSchoole() for i in adminchoose: print(i,adminchoose[i]) yourchoose = int(input("what you want to do")) if yourchoose == 1: #创建班级 garde = homework.Grade("Python班") schoole.createGrade(garde) print("you have create ",schoole.grades) elif yourchoose == 2: course = homework.Course("python",30,13000) # courselist.append(course) schoole.courses.append(course) schoole.makeCourse(schoole.grades[0], course) elif yourchoose == 3: teacher = homework.Teacher("zhang",20,"北京","python") #添加老师 schoole.addTeacher(teacher) #为班级分配老师 schoole.distributionTeacher(schoole.grades[0],teacher) elif yourchoose == 4: #退出程序,并保存信息,这里保存的就是学校的信息,老师,课程,班级等信息 common.saveInfo(schoole) break
所有的类(这里不分开了)
""" 角色:学校、学员、课程、讲师 要求: 1. 创建北京、上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包含,周期,价格,通过学校创建课程 4. 通过学校创建班级, 班级关联课程、讲师 5. 创建学员时,选择学校,关联班级 6. 创建讲师角色时要关联学校, 7. 提供两个角色接口 7.1 学员视图, 可以注册, 交学费, 选择班级, 7.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩 7.3 管理视图,创建讲师, 创建班级,创建课程 8. 上面的操作产生的数据都通过pickle序列化保存到文件里 """ #1 class Schoole: #通过地址创建学校,初始化学校的时候,默认开一个课程,后期可以再添加课程 def __init__(self,addr): self.addr = addr #2.课程必须是实例里的所以定义在实例里面 self.courses = [] #学校中有班级 self.grades = [] #学校中有学生 self.students = {} #学校中有老师 self.teachers = {} #添加课程 def addCourse(self,course): self.courses.append(course) #创建班级 def createGrade(self,grade): self.grades.append(grade) #为班级制定课程 def makeCourse(self,grade,course): grade.course = course #为班级制定老师 def distributionTeacher(self,grade,teacher): #判定这个老师是否符合这个班级 if teacher.know == grade.course.name: grade.teacher = teacher else: print("this teacher %s Not suitable % "%(teacher.name,grade.course.name)) #学生注册 def addStudent(self,student): self.students[student.name] = student #老师注册 def addTeacher(self,teacher): #判断老师是否能够加入到学校 for course in self.courses: if course.name == teacher.know: self.teachers[teacher.name] = teacher #学生通过学校交那个课程的学费 def payTuition(self,student,money,courseName): #这里判断交的钱是否足够,如果足够,将这个学生添加到那个班级里 for i in self.courses: if courseName == self.courses[i].name: course = self.courses[i] if course : if money >= course.price : print("%s is pay %s and join %s"%(student.name,money,course.name)) #将学生添加到班级中 # #根据课程找到老师,根据老师找到班级这里简化一下,班级里面有课程,不跟随老师变化 # for teacher in self.teachers: # if teacher.know == course.name: # #将学生加入到老师所在的班级中 # self.grades for grade in self.grades: if grade.course.name == course.name: grade.students = list().append(student) else: print("%s money is not enough for %s"%(student.name,course.name)) else: print("dont have this %s"%courseName) #3(linux , python , go) class Course: #课程包含 名称,周期,价格 def __init__(self,name,cycle,price): self.name = name self.cycle = cycle self.price = price #4 班级,班级里面包含,学生和讲师,但是班级不能脱离学校直接存在 #实例化班级的时候,其实只需要课程(这里也不需要,统一在学校中处理) class Grade: def __init__(self,name): self.name = name class Person(object): def __init__(self,name,age,addr): self.name = name self.age = age self.addr = addr class Student(Person): #学生有特有的属性,学生需要学习 def study(self): print("%s is study"%self.name) #老师会什么知识,才能教什么课(这里简单一个老师只能教一个课程) class Teacher(Person): def __init__(self,name,age,addr,know): super(Teacher,self).__init__(name,age,addr) self.know = know def teachind(self): print("%s is teaching"%self.name) #这里实例化两个学校 beijingschoole = Schoole("北京") shanghaischoole = Schoole("上海")
common类:
# import os,sys # # sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from core import homework import pickle def getSchoole(): schooleList = [homework.beijingschoole, homework.shanghaischoole] for s in schooleList: print(s.addr) schooleaddr = input("please input your schoole") if schooleaddr == homework.beijingschoole.addr: schoole = homework.beijingschoole else: schoole = homework.shanghaischoole return schoole def saveInfo(schoole): with open("../conf/schoole","wb") as f: pickle.dump(schoole,f) def readInfo(): with open("../conf/schoole","rb") as f: schoole = pickle.load(f) print(schoole.addr,schoole.courses) #测试,可以发现学校的信息已经保存到文件中了 readInfo();