第六周作业——选课系统
Posted 东大网管
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第六周作业——选课系统相关的知识,希望对你有一定的参考价值。
选课系统:
角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
5. 创建讲师角色时要关联学校,
6. 提供两个角色接口
6.1 学员视图, 可以注册, 交学费, 选择班级,
6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
6.3 管理视图,创建讲师, 创建班级,创建课程
7. 上面的操作产生的数据都通过pickle序列化保存到文件里
import pickle import os BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) db_path = BASE_PATH + ‘/db‘ admin_path = db_path + ‘/admin‘ classes_path = db_path + ‘/classes‘ course_path = db_path + ‘/course‘ school_path = db_path + ‘/school‘ student_path = db_path + ‘/student‘ teacher_path = db_path + ‘/teacher‘ # with open(classes_path + ‘/1‘,‘r‘) as f: # for line in f: # print(line) class Admin_base(object): def __init__(self): pass #创建类方法,本身就是类的功能,不需要进行实例化,分别为存入和取出数据 @staticmethod def save_pickle(save_dict,save_path): pickle.dump(save_dict,open(save_path,‘wb‘)) @staticmethod def read_pickle(save_path): read_dict = pickle.load(open(save_path,‘rb‘)) return read_dict #创建学校的方法 @staticmethod def create_school(): school_name = input(‘请输入学校名称:‘).strip() school_add = input(‘请输入学校地址:‘).strip() school_classes = input(‘请输入学校班级:‘).strip() school_course = input(‘请输入学校课程:‘).strip() school_teacher = input(‘请输入老师姓名:‘).strip() save_dict = {} save_dict[‘name‘] = school_name save_dict[‘address‘] = school_add save_dict[‘classes‘] = school_classes save_dict[‘course‘] = school_course save_dict[‘teacher‘] = school_teacher save_path = school_path + ‘/%s%s‘%(school_name,school_add) Admin_base.save_pickle(save_dict,save_path) #创建班级的方法 @staticmethod def create_classes(): classes_name = input(‘请输入班级名称:‘).strip() classes_course = input(‘请输入班级课程:‘).strip() save_dict = {} save_dict[‘name‘] = classes_name save_dict[‘course‘] = classes_course save_path = classes_path + ‘/%s‘%(classes_name) Admin_base.save_pickle(save_dict, save_path) #创建老师 @staticmethod def create_teacher(): teacher_name = input(‘请输入老师名称:‘).strip() teacher_course = input(‘请输入课程名称:‘).strip() save_dict = {} save_dict[‘name‘] = teacher_name save_dict[‘course‘] = teacher_course save_path = teacher_path + ‘/%s‘ % (teacher_name) Admin_base.save_pickle(save_dict, save_path) #创建课程 @staticmethod def create_course(): course_name = input(‘请输入课程名称:‘).strip() course_teacher = input(‘请输入老师名称:‘).strip() save_dict = {} save_dict[‘name‘] = course_name save_dict[‘course‘] = course_teacher save_path = course_path + ‘/%s‘ % (course_name) Admin_base.save_pickle(save_dict, save_path) # 创建学生 @staticmethod def create_student(): student_name = input(‘请输入学生名称:‘).strip() student_course = input(‘请输入课程名称:‘).strip() save_dict = {} save_dict[‘name‘] = student_name save_dict[‘course‘] = student_course save_dict[‘school‘] = ‘None‘ save_path = student_path + ‘/%s‘ % (student_name) Admin_base.save_pickle(save_dict, save_path) class Student(Admin_base): def __init__(self): Admin_base.__init__(self) @staticmethod def student_option(): username = input(‘请输入您的姓名:‘).strip() school_all = os.listdir(school_path) school_name_list = [] for school_name in school_all: school_dict = Admin_base.read_pickle(school_path + ‘/%s‘%(school_name)) school_name_list.append(school_dict[‘name‘]) course_all = os.listdir(course_path) print(‘可选的学校如下:‘,school_name_list) school_option = input(‘请输入您选择的学校:‘).strip() print(‘可选的课程如下:‘,course_all) course_option = input(‘请输入您选择的课程:‘).strip() save_dict = {} save_dict[‘name‘] = username save_dict[‘course‘] = course_option save_dict[‘school‘] = school_option save_path = classes_path + ‘/%s‘ % (username) Admin_base.save_pickle(save_dict, save_path) class Teacher(Admin_base): def __init__(self): Admin_base.__init__(self) @staticmethod def check_course(): course_all = os.listdir(course_path) print(‘课程如下:‘,course_all) course_option = input(‘请选择您的课程:‘).strip() student_all = os.listdir(student_path) student_now_course = [] for student_one in student_all: save_path = student_path + ‘/%s‘%(student_one) save_dict = Admin_base.read_pickle(save_path) if save_dict[‘course‘] == course_option: student_now_course.append(save_dict[‘name‘]) else: pass print(‘您的学生列表:‘,student_now_course) def login_read(): while 1: option = input(‘请选择您要进行的操作:‘ ‘1.管理‘ ‘2.学生‘ ‘3.老师‘ ‘4.退出‘) a = True while a: if option == ‘1‘: username = input(‘请输入用户名:‘) password = input(‘请输入密码:‘) username_path = admin_path + ‘/%s‘%(username) if os.path.exists(username_path): admin_dict = Admin_base.read_pickle(username_path) if password == admin_dict[‘password‘]: print(‘登录成功!‘) option_next = input(‘请选择您要进行的操作:‘ ‘1.新建学校‘ ‘2.新建班级‘ ‘3.新建课程‘ ‘4.新建老师‘ ‘5.新建学生‘ ‘6.返回‘) if option_next == ‘1‘: Admin_base.create_school() break if option_next == ‘2‘: Admin_base.create_classes() break if option_next == ‘3‘: Admin_base.create_course() break if option_next == ‘4‘: Admin_base.create_teacher() break if option_next == ‘5‘: Admin_base.create_student() break if option_next == ‘6‘: a = False else: print(‘输入有误!‘) break else: print(‘密码错误!‘) break else: print(‘用户名错误!‘) break if option == ‘2‘: Student.student_option() break if option == ‘3‘: Teacher.check_course() break if option == ‘4‘: exit() else: print(‘输入错误!‘) break # a = pickle.load(open(school_path + ‘/老男孩北京‘,‘rb‘)) # print(a) # a = os.listdir(admin_path) # print(a) if __name__ == ‘__main__‘: login_read() # login_read() # save_dict = {‘username‘:‘admin‘,‘password‘:‘admin‘} # save_path = admin_path + ‘/admin‘ # Admin_base.save_pickle(save_dict,save_path)
7. 上面的操作产生的数据都通过pickle序列化保存到文件里
以上是关于第六周作业——选课系统的主要内容,如果未能解决你的问题,请参考以下文章