-
Notifications
You must be signed in to change notification settings - Fork 1
/
section_20.py
74 lines (56 loc) · 2 KB
/
section_20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Animal:
def __init__(self, birth_type = "Unknown", appearence = "Unkown", blooded = "Unknown"):
self.__birth_type = birth_type
self.__appearence = appearence
self.__blooded = blooded
@property
def birth_type(self):
return self.__birth_type
@birth_type.setter
def birth_type(self, birth_type):
self.__birth_type = birth_type
@property
def appearence(self):
return self.__appearence
@appearence.setter
def appearence(self, appearence):
self.__appearence = appearence
@property
def blooded(self):
return self.__blooded
@blooded.setter
def blooded(self, blooded):
self.__blooded = blooded
def __str__(self):
return "A {} is {} it has {} it is {}".format(type(self).__name__, self.birth_type, self.appearence, self.blooded)
class Mammal(Animal):
def __init__(self, birth_type = "born alive", appearence = "hair or fur", blooded = "warm blooded", nurse_young = True):
Animal.__init__(self, birth_type, appearence, blooded)
self.__nurse_young = nurse_young
@property
def nurse_young(self):
return self.__nurse_young
@nurse_young.setter
def nurse_young(self, nurse_young):
self.__nurse_young = nurse_young
def __str__(self):
return super().__str__() + "and it has {} they nurse their young".format(self.nurse_young)
class Reptile(Animal):
def __init__(self, birth_type = "born in an egg or born alive", appearence = "dry_scales", blooded = "cold_blooded"):
Animal.__init__(self, birth_type, appearence, blooded)
def main():
animal1 = Animal("born alive")
print(animal1.birth_type)
print(animal1)
mammal1 = Mammal()
print(mammal1)
print(mammal1.birth_type)
print(mammal1.appearence)
print(mammal1.blooded)
print(mammal1.nurse_young)
reptile1 = Reptile()
print(reptile1)
print(reptile1.birth_type)
print(reptile1.appearence)
print(reptile1.blooded)
main()