-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.py
More file actions
69 lines (52 loc) · 1.43 KB
/
inheritance.py
File metadata and controls
69 lines (52 loc) · 1.43 KB
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
class Fruit:
def __init__(self, seeds, flesh, skin):
self._seeds = seeds
self._flesh = flesh
self._skin = skin
@property
def seeds(self):
return self._seeds
@property
def flesh(self):
return self._flesh
@property
def skin(self):
return self._skin
def __str__(self):
return "{name}: I have {skin} skin, {flesh} flesh and {seeds} seeds".format(
name=self.__class__.__name__,
skin=self.skin,
flesh=self.flesh,
seeds=self.seeds
)
class Apple(Fruit):
def __init__(self, colour):
super().__init__(
seeds="small black pips",
flesh="pale and crunchy",
skin="firm yet thin, {}".format(colour)
)
class Braeburn(Apple):
def __init__(self):
super().__init__('red with green patches')
class Bramley(Apple):
def __init__(self):
super().__init__('green')
class Orange(Fruit):
def __init__(self):
super().__init__(
seeds="pale, wrinkly pips",
flesh="juicy, gelatinous, orange",
skin="thick, orange rind"
)
class Tomato(Fruit):
def __init__(self):
super().__init__(
seeds="small and round with a gelatinous case",
flesh="thin and watery",
skin="soft and red"
)
print(Braeburn())
print(Bramley())
print(Orange())
print(Tomato())