Hello everyone!
I want help with my Python3 intermediate course School Catalogue project.
Here it is: Learn Intermediate Python 3 | Codecademy
It throws this error:
Traceback (most recent call last):
File “script.py”, line 59, in
print(c)
TypeError: repr () missing 2 required positional arguments: ‘name’ and ‘numberOfStudents’
Please help, what am I doing wrong?
It’s difficult to tell b/c you’ve not provided any code. So, please provide your (formatted) code that you’ve written so far.
Please follow this guide when posting:
In general, your post will get a good answer if you’ve remembered to do the following:
Always search for existing answers first.
Provide as much information and context as possible.
Format your code.
Follow the Community Guidelines .
Reference Additional Resources
Before Starting a Topic, Search for Existing Answers
Before you start a new topic, check existing posts and use Google to see if your questions have already been addressed. This will very often give you an immediate answer! Crypti…
Here’s 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 setNumberOfStudents(self, newNumberOfStudents):
self.numberOfStudents = newNumberOfStudents
def __repr__(level, name, numberOfStudents):
print("A {} school named {} with {} students".format(self.level, self.name, self.numberOfStudents))
a = School("Codecademy", "high", 100)
print(a.getName())
print(a.getLevel())
a.setNumberOfStudents(200)
print(a.getNumberOfStudents())
class PrimarySchool(School):
def __init__(self, name, numberOfStudents, pickupPolicy, level = "primary"):
super().__init__(name, "primary", numberOfStudents)
self.pickupPolicy = pickupPolicy
def getPickupPolicy(self):
return self.pickupPolicy
def __repr__(self, name, numberOfStudents):
parentRepr = super().__repr__(name, numberOfStudents)
return parentRepr + "The pickup policy is {}".format(pickupPolicy = self.pickupPolicy)
b = PrimarySchool("Codecademy", 300, "Pickup Allowed")
print(b.getPickupPolicy())
class HighSchool(School):
def __init__(self, name, level, numberOfStudents, sportsTeams = []):
super().__init__(name, "high", numberOfStudents)
self.sportsTeams = sportsTeams
def getSportsTeams(self):
return self.sportsTeams
def __repr(sportsTeams):
parent = super().__repr__()
return parent + f" information of our sport Team {', '.join(self.sportsTeams)}"
c = HighSchool("Codecademy High", 500, ["Tennis", "Basketball"])
print(c.getSportsTeams())
print(c)
def __repr__(level, name, numberOfStudents):
should be
def __repr__(self):
You’re to create a method (that requires zero argument when you call it),
so self
should be the only parameter for the function.
1 Like
Okay, now that I have fixed that I get a new type of error.
Traceback (most recent call last):
File “script.py”, line 59, in
print(c)
TypeError: str returned non-string (type NoneType)
yes, the __repr__
function should return a string, not print it.
(change the print
to return
)
1 Like