-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex43.py
More file actions
32 lines (22 loc) · 637 Bytes
/
Copy pathex43.py
File metadata and controls
32 lines (22 loc) · 637 Bytes
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
# Composition
class Chocolate():
def __init__(self):
self.numberOfPiecesLeft = 10
def eatPiece(self):
self.numberOfPiecesLeft -= 1
class Child():
def __init__(self, name):
self.choc = Chocolate()
self.name = name
def eatXPiecesOfChocolate(self, x):
for i in range(x):
self.choc.eatPiece()
print(f"""
You now have {getattr(self.choc, 'numberOfPiecesLeft')}
pieces of chocolate left.
""")
boy = Child(name='Wilson')
print(f"""
You start of with
{getattr(boy.choc, 'numberOfPiecesLeft')} pieces.""")
boy.eatXPiecesOfChocolate(x=4)