#600 · Classes · Intermediate · Find and fix · 70 XP · about 10 min
A school app has a Classroom class. Classroom(name) makes an empty classroom, and the classroom keeps its name. Its methods:
enroll(student) adds a student. A student who is already enrolled is not added again. It returns True if the student was added and False if they were already there.size() returns the number of students.roster() returns a list of the students in the order they enrolled.The code in the editor has two bugs. Each classroom seems fine on its own, but enrolling a student in one classroom adds them to every other classroom too. And enroll says True even for a student who was already in the class.
art = Classroom('Art') music = Classroom('Music') art.enroll('Mia') # returns True art.enroll('Leo') # returns True art.enroll('Mia') # returns False art.roster() # returns ['Mia', 'Leo'] music.size() # returns 0
First solves only, ranked by stars and then time.