-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_object_oriented_programming.py
More file actions
67 lines (59 loc) · 2.37 KB
/
08_object_oriented_programming.py
File metadata and controls
67 lines (59 loc) · 2.37 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
from devices.electronic_device import ElectronicDevice
from devices.laptop import Laptop
from devices.tablet import Tablet
from devices.smart_phone import SmartPhone
class Devices:
""" Create and manage devices. """
def __init__(self):
self.devices = []
self.create_laptops()
self.create_tablets()
self.create_smartphones()
def create_laptops(self):
l1 = Laptop('Dell', 'Inspiron', {'width': 1366,
'height': 768, 'thickness': 10}, 'Windows 10')
l2 = Laptop('Apple MacBook', 'Pro', {'width': 2880,
'height': 1800, 'thickness': 12}, 'macOS Catalina')
l1.restart()
print(l1.basic_info())
l1.connect_wired_lan()
l2.restart()
print(l2.basic_info())
l2.connect_wired_lan()
print('__' * 40)
self.devices.extend([l1, l2])
def create_tablets(self):
t1 = Tablet('Apple iPad', 'Mini', {'width': 768,
'height': 1024, 'thickness': 8}, 66)
t2 = Tablet('Microsoft Surface', 'Pro', {'width': 2736,
'height': 1824, 'thickness': 11}, 13)
t1.restart()
print(t1.basic_info())
t2.restart()
print(t2.basic_info())
print('__' * 40)
self.devices.extend([t1, t2])
def create_smartphones(self):
sp1 = SmartPhone('iPhone', 12, {'width': 828,
'height': 1792, 'thickness': 8}, 'Apple')
sp2 = SmartPhone('Pixel', 'XL', {'width': 411,
'height': 731, 'thickness': 8}, 'Google')
sp1.restart()
sp1.connect_to_wifi()
print(sp1.basic_info())
sp2.restart()
sp2.connect_to_wifi()
print(sp2.basic_info())
print('__' * 40)
self.devices.extend([sp1, sp2])
dv = Devices()
devices = dv.devices
for device in devices:
if isinstance(device, Laptop):
print(device.basic_info(), ' is a laptop')
elif isinstance(device, Tablet):
print(device.basic_info(), ' is a tablet')
elif isinstance(device, SmartPhone):
print(device.basic_info(), ' is a smart phone')
else:
print(device.basic_info(), ' is an electronic device')