Coding challenge

Find error in this code
class Student:
def init(self, name, age):
self.name = name
self.age = age

class Course:
def init(self, name, max_students):
self.name = name
self.max_students = max_students
self.students = []

def add_student(self, student):
if len(self.students) < self.max_students:
self.students.append(student)
return True
return False

physics = Corse("Physics", 3)

students = [
Student("Alice", 20),
Student("Bob", 22),
Student("Charlie", 21),
Student("David", 23),
]

for student in students:
if not physics.add_student(student):
print(f"Cannot add {student.name} to {physics.name}. Course is full.")

print(f"Students in {physics.name}:")
for student in physics.students:
print(f"{student.name} ({student.age} years old)")
Was this page helpful?