-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathvehicles_abc.py
More file actions
42 lines (29 loc) · 913 Bytes
/
vehicles_abc.py
File metadata and controls
42 lines (29 loc) · 913 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
33
34
35
36
37
38
39
40
41
42
from abc import ABC, abstractmethod
class Vehicle(ABC):
def __init__(self, make, model, color):
self.make = make
self.model = model
self.color = color
@abstractmethod
def start(self):
raise NotImplementedError("This method must be implemented")
@abstractmethod
def stop(self):
raise NotImplementedError("This method must be implemented")
@abstractmethod
def drive(self):
raise NotImplementedError("This method must be implemented")
class Car(Vehicle):
def start(self):
print("The car is starting")
def stop(self):
print("The car is stopping")
def drive(self):
print("The car is driving")
class Truck(Vehicle):
def start(self):
print("The truck is starting")
def stop(self):
print("The truck is stopping")
def drive(self):
print("The truck is driving")