I'm pretty new to Python and I'm trying to understand multiple inheritance. Below I have a code, where I need to create an array of Animals.
- An Animal can be Domesticated and Feline
- A Tiger is a Feline Animal
- A Cat is a Domesticated & Feline Animal
Here are the classes:
class Animal:
def __init__(self, birthDate, type, name, numOfLegs):
self.birthDate = birthDate
self.type = type
self.name = name
self.numOfLegs = numOfLegs
class Domesticated(Animal):
def __init__(self, birthDate, type, name, numOfLegs, lastVetCheck):
super().__init__(birthDate, type, name, numOfLegs)
self.lastVetCheck = lastVetCheck
class Feline(Animal):
def __init__(self, birthDate, type, name, numOfLegs, mustacheLength):
super().__init__(birthDate, type, name, numOfLegs)
self.mustacheLength = mustacheLength
class Cat(Feline, Domesticated):
def __init__(self, mustacheLength, numOfLegs, name, type, bDate, vetDate):
Feline.__init__(self, bDate, type, name, numOfLegs, mustacheLength)
Domesticated.__init__(self,bDate, type, name, numOfLegs, vetDate)
class Tiger(Feline):
def __init__(self, birthDate, type, name, numOfLegs, mustacheLength):
super().__init__(birthDate, type, name, numOfLegs, mustacheLength)
Rese of the code:
animal_array = []
my_cat = Cat('4', '4', 'Tom', 'Mammal', '1.2.3', '3.4.5')
my_animal = Animal('6.7.8', 'Reptile', 'Rafael', '4')
my_tiger = Tiger('1.1.1', 'Mammal', 'Tiger', '4', '9')
animal_array.append(my_cat)
animal_array.append(my_animal)
animal_array.append(my_tiger)
I receive this error:
Traceback (most recent call last):
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 33, in <module>
my_cat = Cat('4', '4', 'abc', 'mammal', '1.2.3', '3.4.5')
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 23, in __init__
Feline.__init__(self, bDate, type, name, numOfLegs, mustacheLength)
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 17, in __init__
super().__init__(birthDate, type, name, numOfLegs)
TypeError: __init__() missing 1 required positional argument: 'lastVetCheck'
Now I'm sure that it's a simple issue, probably my classes structuring is bad, though I have no clue what to fix. I sure can use any structuring tips since I'm pretty new to OO.