-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7inheritance.py
32 lines (26 loc) · 1.07 KB
/
7inheritance.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
# 7. Implement a class inheritance as following
class Devices:
def __init__(self, brand, colour):
self.brand = brand
self.colour = colour
class Smartphone(Devices):
def __init__(self, brand, colour, operating_system, model):
super().__init__(brand, colour)
self.operating_system = operating_system
self.model = model
class Laptop(Devices):
def __init__(self, brand, colour, processor, storage_capacity):
super().__init__(brand, colour)
self.processor = processor
self.storage_capacity = storage_capacity
class SmartWatch(Devices):
def __init__(self, brand, colour, waterproof, heartsensor):
super().__init__(brand, colour)
self.waterproof = waterproof
self.heartsensor = heartsensor
smartphone = Smartphone("Samsung", "Black", "Android", "Galaxy S23 Ultra")
laptop = Laptop("Dell", "Silver", "Intel i7", "512GB SSD")
smartwatch = SmartWatch("Apple", "White", True, True)
print("Smartphone:", smartphone.__dict__)
print("Laptop:", laptop.__dict__)
print("Smartwatch:", smartwatch.__dict__)