|
6 | 6 | class Animal(): |
7 | 7 | """Base class for animals. Not meant to be instantiated.""" |
8 | 8 |
|
9 | | - def __init__(self, color): |
| 9 | + def __init__(self, color, number_of_legs): |
10 | 10 | self.species = self.__class__.__name__ |
11 | 11 | self.color = color |
| 12 | + self.number_of_legs = number_of_legs |
12 | 13 |
|
13 | 14 | def __repr__(self): |
14 | 15 | return f'{self.color} {self.species}, {self.number_of_legs} legs' |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class TwoLeggedAnimal(Animal): |
18 | 19 | def __init__(self, color): |
19 | | - super().__init__(color) |
20 | | - self.number_of_legs = 2 |
| 20 | + super().__init__(color, 2) |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class FourLeggedAnimal(Animal): |
24 | 24 | def __init__(self, color): |
25 | | - super().__init__(color) |
26 | | - self.number_of_legs = 4 |
| 25 | + super().__init__(color, 4) |
27 | 26 |
|
28 | 27 |
|
29 | 28 | class ZeroLeggedAnimal(Animal): |
30 | 29 | def __init__(self, color): |
31 | | - super().__init__(color) |
32 | | - self.number_of_legs = 0 |
| 30 | + super().__init__(color, 0) |
33 | 31 |
|
34 | 32 |
|
35 | 33 | class Wolf(FourLeggedAnimal): |
36 | 34 | """Class for creating 4-legged wolves of any color""" |
37 | 35 |
|
38 | | - def __init__(self, color): |
39 | | - super().__init__(color) |
40 | | - |
41 | | - |
42 | 36 | class Sheep(FourLeggedAnimal): |
43 | 37 | """Class for creating 4-legged sheep of any color""" |
44 | 38 |
|
45 | | - def __init__(self, color): |
46 | | - super().__init__(color) |
47 | | - |
48 | | - |
49 | 39 | class Snake(ZeroLeggedAnimal): |
50 | 40 | """Class for creating 0-legged snakes of any color""" |
51 | 41 |
|
52 | | - def __init__(self, color): |
53 | | - super().__init__(color) |
54 | | - |
55 | | - |
56 | 42 | class Parrot(TwoLeggedAnimal): |
57 | 43 | """Class for creating 2-legged parrots of any color""" |
58 | | - |
59 | | - def __init__(self, color): |
60 | | - super().__init__(color) |
0 commit comments