Compute average for a subject
Input
c = build_sample_classroom(); c.average_grade('Math')
Output
85.0
The sample classroom has three Math grades: 90 (Alice), 80 (Bob), 85 (Charlie). The average is (90+80+85)/3 = 85.0.
Full lesson preview
Design a small object model for a classroom using composition: Students belong to a Classroom and each student has grades in Subjects.
Problem statement
Task
Examples
Input
c = build_sample_classroom(); c.average_grade('Math')
Output
85.0
The sample classroom has three Math grades: 90 (Alice), 80 (Bob), 85 (Charlie). The average is (90+80+85)/3 = 85.0.
Input format
Output format
Constraints
Samples
Input
build_sample_classroom().top_student('Science')
Output
Bob
In the sample classroom, Bob has the highest Science grade (90) compared to Alice (80).