-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDALIGDIG_final_exam_problem_2.py
74 lines (56 loc) · 1.77 KB
/
DALIGDIG_final_exam_problem_2.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
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
68
69
70
71
72
73
74
# Parent Class
class Vehicle():
wheels = None
def __init__(self, wheels):
self.wheels = wheels
def display(self):
print("\nThe vehicle has {} wheels.".format(self.wheels))
def accelerate(self):
print("It is now accelerating...")
# Child Class
class Car(Vehicle):
brand = ''
def __init__(self, brand, wheels):
self.brand = brand
Vehicle.__init__(self, wheels)
def display(self):
super().display()
print("brand is {}.".format(self.brand))
# Child Class
class Motorcycle(Vehicle):
brand = ''
def __init__(self, brand, wheels):
self.brand = brand
Vehicle.__init__(self, wheels)
def display(self):
super().display()
print("Brand is {}.".format(self.brand))
# Child of Car Class
class Estate(Car):
model = ''
gears = 0
def __init__(self, model, gears, brand, wheels):
self.model = model
self.gears = gears
Car.__init__(self, brand, wheels)
def display(self):
super().display()
print(" {} has {} gears.".format(self.model , self.gears))
# Child of Motorcycle Class
class Scooter(Motorcycle):
model = None
gears = None
def __init__(self, model, gears, brand, wheels):
self.model = model
self.gears = gears
Motorcycle.__init__(self, brand, wheels)
def display(self):
super().display()
print(" {} has {} gear.".format(self.model , self.gears))
if __name__ == "__main__":
e = Estate(model="S", gears=5, wheels=4, brand="Tesla")
e.display() # overrides
e.accelerate()
s = Scooter(model="Mio", gears=1, wheels=2, brand="Yamaha")
s.display() # overrides
s.accelerate()