0

I'm learning how inheritance works in python, though I can't get through this error, this is my code:

 class Animal:  
    def __init__(self, species, paws, height, weight):  
        self.species = species  
        self.paws = paws  
        self.height = height  
        self.weight = weight  
    def __str__(self):  
        return "Questo animale è un {} ed ha {} zampe, è alto {}cm e pesa {}kg".format(self.species, self.paws, self.height, self.weight)  
    def __del__(self):  
        return "Animale cancellato dal programma"  
    
class Dog(Animal):  
    def __init__(self, species, paws, height, weight, race, color):  
        super(Animal, self).__init__(species, paws, height, weight)  
        self.race = race  
        self.color = color  
    def __str__(self):  
        txt = super(Animal, self).__str__()  
        txt += f", è un {self.race} di colore {self.color}."    
        return txt  
    
                 
a1 = Animal("mammifero", 4, 50, 22)  
a2 = Dog("mammifero", 4, 60, 40, "Rottweiler", "nero")  
print(a1)  
print(a2)  

What did I do wrong?

ddejohn
  • 8,775
  • 3
  • 17
  • 30
Alex
  • 11
  • 6

0 Answers0