def choose_class(teacher, teacher_list): """ :param teacher: 当前登录系统的老师 :param teacher_list: 所有老师的列表 :return: """ # 加载所有的Course course_list = UserDb.load_from_memory('Course') for c in course_list: if not c.course_teacher: print(c) choice = input('请选择要教授的课程:\n') if choice in set([c.course_name for c in course_list]): # 找到教师要教授课程的索引位置,并将老师姓名加入到课程中 index = -1 for t in course_list: index += 1 if t.course_name == choice: break course_list[index].course_teacher = teacher.name UserDb.write_to_memory('Course', course_list) choose_course = course_list[index] # 找到老师列表中国老师的索引位置,并将课程加入到列表中 index = -1 for t in teacher_list: index += 1 if t.name == teacher.name: break teacher_list[index].course_list.append(choose_course) UserDb.write_to_memory('Teacher', teacher_list)
def add_course(self): course_name = input('请输入课程名称:\n').strip() course_loc = input('请输入课程位置:\n').strip() course_price = input('请输入课程价格:\n').strip() course_time = input('请输入课程时间:\n').strip() c = Course(course_name, course_loc, course_price, course_time) self.course_list.append(c) UserDb.write_to_memory('Course', self.course_list) print(c)
def scoring(teacher): """ :param teacher: 当前登录系统的老师 :return: """ course_list = UserDb.load_from_memory('Course') c_index = -1 for c in course_list: c_index += 1 # 记录当前老师教授课程在课程列表中的位置 if c.course_teacher == teacher.name: print('请给学生打分:\n') s_index = 0 # 遍历选该课程的所有学生并打分 for sc in c.course_student: score = input(sc.student_name + ":的分数为\n") course_list[c_index].course_student[s_index].score = score print(sc.student_name + ":分数为" + score) UserDb.write_to_memory('Course', course_list)
def choose_class(local_student): # 加载课程列表,输出所有没有老师上课的课程 course_list = UserDb.load_from_memory('Course') for c in course_list: if c.course_teacher: print(c) choice = input('请选择要教授的课程:\n') if choice in set([c.course_name for c in course_list]): student_list = UserDb.load_from_memory('Student') # 找到当前学生在学生列表中的位置,并增加选课信息 index = -1 for t in student_list: index += 1 if t.name == local_student.name: break student_list[index].add_course(choice) # 找到当前课程在课程列表中的位置,并增加学生信息 index = -1 for t in course_list: index += 1 if t.course_name == choice: break course_list[index].course_student.append( StudentScore(local_student.name, '-1')) # 将Course和Student列表存入到文件中 UserDb.write_to_memory('Course', course_list) UserDb.write_to_memory('Student', student_list)
def see_score(local_student): """ 学生查看成绩的时候流程 遍历学生course_list,得到所选的每一个课程: 遍历所有课程列表course_list,得到学生选课的course类: 遍历课程中所有学生的列表: 如果当前学生生姓名与分数姓名一样,输入学生成绩 :param local_student: :return: """ course_list = UserDb.load_from_memory('Course') for select_course in local_student.course_list: for course in course_list: if course.course_name == select_course: for sc in course.course_student: if sc.student_name == local_student.name: print('学生姓名:{},所选课程:{},学生成绩:{}'.format( local_student.name, course.course_name, sc.score))
def see_course(teacher): print('您教授的课程列表如下:\n') course_list = UserDb.load_from_memory('Course') for c in course_list: if c.course_teacher == teacher.name: print(c)
def add_teacher(self): teacher_name = input('请输入老师的名称:\n').strip() t = Teacher(teacher_name) self.teacher_list.append(t) UserDb.write_to_memory('Teacher', self.teacher_list) print('增加教师:' + t.name)
def __init__(self): self.teacher_list = UserDb.load_from_memory('Teacher') self.course_list = UserDb.load_from_memory('Course') self.student_list = UserDb.load_from_memory('Student')