def split_course(course, index): before = Course(course.semester_names[:index], None, course.is_1x) after = Course(course.semester_names[index:index + 1], None, course.is_1x) for i in range(index + 1): # if i == len(course.semester_names) - 1: # continue name = course.semester_names[i] if i < index: before.add(name, course.get(name)) else: after.add(name, course.get(name)) return (before, after)
def average_age_by_season(course): spring = Course() summer = Course() fall = Course() for sem in course.semester_names: semester = course.get(sem) if semester.season == 'spring': spring.add(sem, semester) elif semester.season == 'summer': summer.add(sem, semester) else: fall.add(sem, semester) spring_age = [ entry.age if (entry.age != None and entry.age > 7) else np.nan for entry in spring.get_all_entries() ] summer_age = [ entry.age if (entry.age != None and entry.age > 7) else np.nan for entry in summer.get_all_entries() ] fall_age = [ entry.age if (entry.age != None and entry.age > 7) else np.nan for entry in fall.get_all_entries() ] spring_percent = [ 1 if (entry.age != None and entry.age >= 12 and entry.age <= 19 and (entry.education_level == 'hs' or entry.education_level == 'jhs')) else 0 for entry in spring.get_all_entries() ] summer_percent = [ 1 if (entry.age != None and entry.age >= 12 and entry.age <= 19 and (entry.education_level == 'hs' or entry.education_level == 'jhs')) else 0 for entry in summer.get_all_entries() ] fall_percent = [ 1 if (entry.age != None and entry.age >= 12 and entry.age <= 19 and (entry.education_level == 'hs' or entry.education_level == 'jhs')) else 0 for entry in fall.get_all_entries() ] print("spring age:", np.nanmean(spring_age), np.nanstd(spring_age)) print("summer age:", np.nanmean(summer_age), np.nanstd(summer_age)) print("fall age:", np.nanmean(fall_age), np.nanstd(fall_age)) print("spring age:", np.mean(spring_percent)) print("summer age:", np.mean(summer_percent)) print("fall age:", np.mean(fall_percent))
from classes import Teacher, Student, Course compsci = Course("Computer Science 101", "CS101") maria = Student("Maria", "Martinez") joe = Student("Joe", "Smith") ashven = Student("Ashven", "Matthew") imani = Teacher("Imani", "Matthews") compsci.add([maria, joe, ashven]) compsci.set_teacher(imani) print(compsci.teacher, compsci.students) joe.addgrade(compsci, 80) joe.addgrade(compsci, 89) joe.addgrade(compsci, 100) print() print("GPA for {} is {:.2f}.".format(joe, joe.gpa_for(compsci)))