School Catalogue

Hi so I am working on this project here( and I am stuck on step 7 where it asks you to test your code.
here is my code:

class School:

  def __init__(self, name, level, numberOfStudents): = name
    self.level = level
    self.numberOfStudents = numberOfStudents

  def getName(self):

  def getLevel(self):
    return self.level

  def getNumberOfStudents(self):
    return self.numberOfStudents
  def __repr__(self):
    return f"A {self.level} school name {} with {self.numberOfStudents} students."

mySchool = School("Clint", "high", 100)

Now here is the error and output:

A high school name Clint with 100 students.
Traceback (most recent call last):
  File "", line 25, in <module>
AttributeError: 'School' object has no attribute 'setNumberOfStudents'

I can not figure out how to fix the attribute even though I am doing it as the project is instructing. any hints of what I am doing wrong are appreciated. Thank you.

you appear to have missed step 5 - creating the setter.

I thought the setter was: = name
self.level = level
self.numberOfStudents = numberOfStudents

I could be wrong. the cheat sheet is not very clear in this exercise. Happy 4th by the way.

That’s the constructor. It is where the object has its properties ‘set’ initially.
But a setter is a function you use to alter a property without accessing it directly.
So, for this exercise it could be;

def setNumberOfStudents(self, number):
   self.numberOfStudents = number

Hope that helps.
(I’m English, but be sure to have a happy 4th yourself)

ah okay, thanks. that makes much more sense. apologies if I made a social faux pas with the happy 4th though. Thank you for your help.

1 Like

Happy to help.
No need to apologise, it’s just not a thing over here (probably because we’re the folks most countries gained independence from, lol)

Have fun!

1 Like

you too, take care. and thanks again