-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_2.py
More file actions
48 lines (40 loc) · 1.17 KB
/
OOP_2.py
File metadata and controls
48 lines (40 loc) · 1.17 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
class Box:
def __init__(self, size):
self.size = size
self.count = []
def check(self):
print("Free space in the box now:", self.size)
if len(self.count) != 0:
print('Items in the box:', ', '.join(self.count))
else:
print('There is nothing in the box')
return self.size
class Create:
def __init__(self, name,size):
self.name = name
self.in_the_box = 'no'
self.size = size
def check(self):
print("Is", self.name, "in the box? - ", self.in_the_box)
print('The size of the', self.name, 'is', self.size)
return self.in_the_box
def put_in_the(self, box):
if box.size >= self.size:
self.in_the_box = 'yes'
box.size -= self.size
box.count.append(self.name)
print(self.name, 'is put in the box')
else:
print('There is no place in the box for', self.name)
return self.check(), box.check()
krug = Create('krug', 1)
kv = Create('kvadrat', 4)
tr = Create('treugolnik', 6)
box = Box(10)
box.check()
print()
krug.put_in_the(box)
print()
kv.put_in_the(box)
print()
tr.put_in_the(box)