-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection_10.py
More file actions
53 lines (37 loc) · 1.15 KB
/
section_10.py
File metadata and controls
53 lines (37 loc) · 1.15 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
# Inheritance
class Vehicle:
def __init__(self, brand, model, year):
self.brand = brand
self.model = model
self.year = year
def start(self):
print(f'{self.__class__.__name__}: is starting' )
def stop(self):
print(f'{self.__class__.__name__}: is stopping' )
class Car(Vehicle):
def __init__(self, brand, model, year, doors, wheels):
super().__init__(brand, model, year)
self.doors = doors
self.wheels = wheels
class Bike(Vehicle):
def __init__(self, brand, model, year, wheels):
super().__init__(brand, model, year)
self.wheels = wheels
############
### MAIN ###
############
if __name__ == '__main__':
# # Uncomment to test
# vehicle_01 = Vehicle('Brand_A', 'Model_A', 1910)
# vehicle_01.start()
# vehicle_01.stop()
# Uncomment to test
car_01 = Car('Brand_B', 'Model_B', 2020, 3, 4)
print(car_01.__dict__)
car_01.start()
car_01.stop()
# Uncomment to test
bike_01 = Bike('Brand_C', 'Model_C', 2010, 2)
print(bike_01.__dict__)
bike_01.start()
bike_01.stop()