Homework

Grade School

Write a small program that stores school enrolment information in a class called School.

This is meant to practice classes, dictionaries & lists in Python. No actual database needed.

school = School("Haleakala Hippy School")

If no students have been added, the data should be empty:

school.data
# => {}

When you add a student, they get added to the correct grade. For example, James Smith is in grade 2:

school.add("James Smith", 2)
school.data
# => {2: ["James Smith"]}

You can, of course, add several students to the same grade, and students to different grades.

school.add("Phil Brown", 2)
school.add("Jennifer Wu", 3)
school.add("Bobby Tables", 1)
school.data
# => {2: ["James Smith", "Phil Brown"], 3: ["Jennifer Wu"], 1: ["Bobby Tables"]}

Also, you can ask for all the students in a single grade:

school.grade(2)
# => ["James Smith", "Phil Brown"]

Make sure it works with more than one school, and keeps the information separate:

other_school = School("East Hills Primary")
other_school.data
# => {}

Last updated