11

 avatar
unknown
plain_text
3 years ago
1.9 kB
7
Indexable
class School:
    def __init__(self, name, level, numberOfStudents):
        self.name = name
        self.level = level
        self.numberOfStudents = numberOfStudents

    def get_name(self):
        return self.name

    def get_level(self):
        return self.level

    def get_numberOfStudents(self):
        return self.numberOfStudents

    def set_numberOfStudents(self, no):
        self.numberOfStudents = no

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

class PrimarySchool(School):

    def __init__(self, name, numberOfStudents, pickupPolicy): # here we call attr with which we will establ object
        super().__init__(name, "primary", numberOfStudents) # here we call that the same attributes that exist in the
        self.pickupPolicy = pickupPolicy # parent class are collected in the same way as in parent class

    def get_pickupPolicy(self):
        return self.pickupPolicy

    def __repr__(self):
        r = super().__repr__()
        return(r+ f"s {self.pickupPolicy}")

class HighSchool(School):

    def __init__(self, name, numberOfStudents, sportsTeams, sextype):
        super().__init__(name, "high", numberOfStudents)
        self.sportsTeams = sportsTeams
        self.sextype = sextype

    def get_sportsTeams(self):
        return self.sportsTeams

    def __repr__(self):
        l = super().__repr__()
        return (l + f" with such teams as {self.sportsTeams} loving {self.sextype}")


a = School("1st norm school", "normal", 50)
print(a)

print(a.numberOfStudents)

b =  PrimarySchool("Codecademy", 300, "Pickup Allowed")
print(b)
print(b.numberOfStudents)

c = HighSchool("1st high sch", 500, ["Dynamo", "Shack"], "anal")
print(c)
print(c.numberOfStudents)
print(c.__dict__)

Editor is loading...