School Catalogue

Hi so I am working on this project here(https://www.codecademy.com/courses/learn-intermediate-python-3/projects/python-school-catalogue) 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):

    self.name = name
    self.level = level
    self.numberOfStudents = numberOfStudents

  def getName(self):
    return self.name

  def getLevel(self):
    return self.level

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

mySchool = School("Clint", "high", 100)
print(mySchool)
print(mySchool.getName())
print(mySchool.getLevel())
mySchool.setNumberOfStudents(200)
print(mySchool.getNumberOfStudents())

Now here is the error and output:

A high school name Clint with 100 students.
Clint
high
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    mySchool.setNumberOfStudents(200)
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.

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

I thought the setter was:

self.name = 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.

Hi,
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