School Catalogue (Learn Intermediate Python 3)

Hi i’m trying to complete the project School Catalogue under the course Learn Intermediate Python 3 but keep running issues and I cannot find any get through video or solutions which is frustrating.
I don’t know what’s wrong with my code for the pickuppolicy property, the terminal kept showing
Traceback (most recent call last):
File “script.py”, line 45, in
e2 = PrimarySchool(“codecademy”, 60, “Pickup Allowed”)
TypeError: init() missing 1 required positional argument: ‘pickupPolicy’

class School:
  def __init__(self, name, level, numberOfStudents):
    self._name = name
    self._level = level
    self._numberOfStudents = numberOfStudents

  @property
  def name(self):
    return self._name
  
  @property
  def level(self):
    return self._level
  
  @property
  def numberOfStudents(self):
    return self._numberOfStudents
  
  @numberOfStudents.setter
  def numberOfStudents(self, num):
    self._numberOfStudents = num
  
  def __repr__(self):
    return(f"A {self.level} school name {self.name} with {self.numberOfStudents} students")

class PrimarySchool(School):
  def __init__(self, name, level, numberOfStudents, pickupPolicy):
    super().__init__(name, "primary", numberOfStudents)
    self._pickupPolicy = pickupPolicy
  
  @property
  def pickupPolicy(self):
    return self._pickupPolicy


e1 = School("codecademy", "middle", 50)
print(e1)
e2 = PrimarySchool("codecademy", 60, "Pickup Allowed")
print(e2)
1 Like

I think you might be looking at the wrong spot as it’s nothing to do with the decorators, just re-read that error carefully as it directs you to the problem. You have a function that’s missing a positional argument. Have a look at the definition- ...__(self, name, level, numberOfStudents, pickupPolicy), there are 5 parameters (one which is passed by default when used from an instance). How many arguments have you used in the call you make on line 45?

I’ve been confused with the arguments i should pass in using superclass and subclass. I thought I still need to pass the level parameter even if we want to pass a default value to it in the constructor. Could you please explain more on this?
Below is the correct code, thank you!

class PrimarySchool(School):
  def __init__(self, name, numberOfStudents, pickupPolicy):
    super().__init__(name, "primary", numberOfStudents)
    self.pickupPolicy = pickupPolicy

What you describe is a little confusing (I recognise the lesson but a link would be helpful in the future). Your issue is that you’re simply not passing enough arguments to your PrimarySchool initialiser, how you fix this is up to you (either pass the correct number of arguments of or alter the call signature).

Your error occurs because of this line:
e2 = PrimarySchool("codecademy", 60, "Pickup Allowed")

At present your PrimarySchool.__init__ function takes 5 arguments-
def __init__(self, name, level, numberOfStudents, pickupPolicy)

There simply aren’t enough arguments for that call, even as a method. At present you have a call that effectively acts like this:
PrimarySchool.__init__(self=e2, "codecademy", 60, "Pickup Allowed")

But there’s only 4 arguments when 5 are expected, either pass level or bump it from the call signature.

4 Likes

i wish there was a video for this exercise, got pretty confused!! with instructions and clues, i think keeping track of this sort of exercise is a bit challenging…
Create the School Class

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 setNumberOfStudents(self, newNumberOfStudents):
self.numberOfStudents = newNumberOfStudents
def repr(self):
print( “A {self.level} school named {self.name} {self.numberOfStudents} students”)

mySchool = School(“Codecademy”, “high”, 100)
#print(mySchool)
#print(mySchool.getName())
#print(mySchool.getLevel())
#mySchool.setNumberOfStudents(200)
#print(mySchool.getNumberOfStudents())
class PrimarySchool(School):
def init(self, name, numberOfStudents, pickupPolicy):
super().init(name, “primary”, numberOfStudents)
self.pickupPolicy = pickupPolicy
def getPickupPolicy(self, pickupPolicy):
return self.pickupPolicy
def repr(self):
PrimarySchool = super().repr()
return PrimarySchool + “The pickup policy is {pickupPolicy}”.format(pickupPolicy = self.pickupPolicy)

testSchool = PrimarySchool(“Codecademy”, 300, “Pickup Allowed”)
#print(testSchool.getPickupPolicy())
print(testSchool)

i have an error that says:

line 34, in repr
return PrimarySchool + “The pickup policy is {pickupPolicy}”.format(pickupPolicy = self.pickupPolicy)

TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘str’
does anyone have an idea what my error is? i tried everything i am about to give up … any help is very welcomed

If you’re posting code to the forums please see How do I format code in my posts?. You should also be aware that this a slightly older solved thread, in the future it’d be worthwhile starting a new one and simply referencing this one (only if this thread is actually relevant).

I think your issue comes in with the fact that __repr__ and __str__ must return a string type. Using print to send it to the console is not how they’re designed to work (they must be able to pass strings to multiple different places). If that’s not the major issue or it doesn’t solve your problem please consider making a new post with your issue, thanks :slightly_smiling_face:.

Having a bit of trouble on the dunder repr of the child class after the parent School class.

class School:
  def __init__(self, name, level, numberofstudents):
    self.name = name
    self.level = level
    self.numberofstudents = numberofstudents
  
  def __repr__(self):
    return "A {level} school named {name} with {numberofstudents} students".format(level= self.level, name = self.name, numberofstudents=self.numberofstudents)

  def getname(self):
    return self.name
  
  def getlevel(self):
    return self.level
  
  def getnumberofstudents(self):
    return self.numberofstudents

  def setnumberofstudents(self, newnumberofstudents):
    self.numberofstudents = newnumberofstudents

mySchool = School("Codecademy", "High", 100)
print(mySchool)
print(mySchool.getname())
print(mySchool.getlevel())
mySchool.setnumberofstudents(200)
print(mySchool.getnumberofstudents())

class PrimarySchool(School):
  def __init__(self, name, numberofstudents, pickuppolicy, level = 'primary'):
    super().__init__(self,name,numberofstudents)
    self.pickuppolicy = pickuppolicy
  
  def getpickuppolicy(self):
    return self.pickuppolicy

  def __repr__(self):
    parentRepr = super().__repr__(self)
    return parentRepr + "The pickup policy is {pickuppolicy}.".format(pickuppolicy=self.pickuppolicy)
    
testSchool = PrimarySchool("Codecademy", 300, "Pickup Allowed")
print(testSchool.getpickuppolicy())
print(testSchool.getlevel)
print(testSchool)

the error i get is:

Traceback (most recent call last):
File “script.py”, line 43, in
print(testSchool.getlevel)
File “script.py”, line 38, in repr
parentRepr = super().repr(self)
TypeError: repr() takes 1 positional argument but 2 were given

Not sure what the issue is. I’m pretty sure the code only suppose to take the pickuppolicy argument. Where is the 2nd arguement?

If you’re using super you don’t need to pass self as an argument, it’s already a method and self would already be passed as the first argument (that’s why it complains about two arguments).

I understand this is in relation to the same lesson as the original post but it’s a different question on a solved post, in the future it would be best to make a new post for it. Ta.

1 Like

class School:
def init(self, name, level, numberOfStudents):
self.name = name
self.level = level
self.numberOfStudents = numberOfStudents

def __repr__(self):
    return (
        'A {level} school named {name} with {numberOfStudents} students'.format(level=self.level, name=self.name,
                                                                                numberOfStudents=self.numberOfStudents))

def get_name(self):
    return self.name

def get_level(self):
    return self.level

def get_number_of_students(self):
    return self.numberOfStudents

def set_number_of_students(self, numberOfStudents):
    self.numberOfStudents = numberOfStudents

a = School(‘a’, ‘high’, ‘10’)

class PrimarySchool(School):
def init(self, name, numberOfStudents, pickUpPolicy):
self.pickUpPolicy = pickUpPolicy
super().init(name, “primary”, numberOfStudents)

def __repr__(self):
    rep = super().__repr__()
    return rep + "The pickup policy is {pickUpPolicy}".format(pickUpPolicy=self.pickUpPolicy)

def get_pickup(self):
    return self.pickUpPolicy

b = PrimarySchool(‘code’, ‘89126’, ‘NO’)

class HighSchool(School):
def init(self, name, numberOfStudents, sportsTeams=):
self.name = name
self.numberOfStudents = numberOfStudents
self.sportsTeams = sportsTeams

def get_sports_teams(self):
    return self.sportsTeams

c = HighSchool(“Codecademy High”, 500, [“Tennis”, “Basketball”])
print(c.get_name())

AH yes, I got it! Thank you very much, I can move onto the rest of the steps now.

And yes, I’ll remember to make a seperate topic for the future.

Thank you for taking the time.

1 Like