python选课系统完整版
Posted linshuhui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python选课系统完整版相关的知识,希望对你有一定的参考价值。
一、需求
角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linuxpy 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
5. 创建讲师角色时要关联学校,
6. 提供两个角色接口
7. 学员视图, 可以注册, 交学费, 选择班级,
8. 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
9. 管理视图,创建讲师, 创建班级,创建课程
10. 上面的操作产生的数据都通过pickle序列化保存到文件里
二、代码
import os, pickle BASR_DIR = os.path.dirname(os.path.abspath(__file__)) __school_db = os.path.join(BASR_DIR, ‘school_db‘) __teacher_db = os.path.join(BASR_DIR, ‘teacher_db‘) def init_database(): if not os.path.exists(__school_db): bj = School(‘北京‘, ‘北京沙河‘) sh = School(‘上海‘, ‘上海市‘) dic = {bj: [], sh: []} file_opration(__school_db, ‘wb‘, dic) if not os.path.exists(__teacher_db): dic = {} file_opration(__teacher_db, ‘wb‘, dic) def file_opration(file, mode, *args): if mode == ‘wb‘: with open(file, mode)as f: f.write(pickle.dumps(args[0])) if mode == ‘rb‘: with open(file, mode) as f: return pickle.loads(f.read()) class School: def __init__(self, name, addr): self.name = name self.addr = addr def msg_display(self): print(‘校区名称: 33[1;32m%s 33[0m 校区位置: 33[1;32m %s 33[0m‘ % (self.name, self.addr)) def create_course(self, course_obj, school_dict, file): school_dict[self].append(course_obj) file_opration(file, ‘wb‘, school_dict) class Course: def __init__(self, name, price, time): self.name = name self.price = price self.time = time self.classes = {} def msg_display(self): print(‘【课程】: 33[1;32m%s 33[0m 【价格】: 33[1;32m%s 33[0m 【周期】: 33[1;32m%s 33[0m‘ % ( self.name, self.price, self.time)) def create_class(self, class_obj): self.classes[class_obj.name] = class_obj class Class: def __init__(self, name): self.name = name self.students = {} self.teachers = {} class Teacher: def __init__(self, name): self.name = name class Student: def __init__(self, name, age): self.name = name self.age = age def main_center(): flag = True while flag: print(‘******** 33[1;35m欢迎来到管理员系统 33[0m!**********‘) choice = input(‘输入1:增加课程 输入2:增加班级 输入3:增加教师 输入4:返回 ‘).strip() school_dict = file_opration(__school_db, ‘rb‘) if choice == ‘1‘: for i in school_dict: i.msg_display() while 1: school_choice = input("请输入需要创建课程的校区名称: ") if school_choice == ‘北京‘ or school_choice == ‘上海‘: for i in school_dict: if i.name == school_choice: school_obj = i course_name = input("请输入课程名称 ") price = input("请输入课程价格 ") time = input("请输入课程周期 ") course_obj = Course(course_name, price, time) school_obj.create_course(course_obj, school_dict, __school_db) print("