-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 9.py
More file actions
58 lines (46 loc) · 1.31 KB
/
Assignment 9.py
File metadata and controls
58 lines (46 loc) · 1.31 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
class Vehicle:
def __init__(self, make, model, year, weight):
self.make = make
self.model = model
self.year = year
self.weight = weight
self.needsMaintenance = False
self.tripsSinceMaintenance = 0
class Car(Vehicle):
def __init__(self, make, model, year, weight):
super().__init__(make, model, year, weight)
self.isDriving = False
def drive(self):
self.isDriving = True
self.tripsSinceMaintenance += 1
self.needsMaintenance = self.tripsSinceMaintenance > 100
def stop(self):
self.isDriving = False
def repair(self):
self.tripsSinceMaintenance = 0
self.needsMaintenance = False
mustang = Car('Ford', 'Mustang', 2016, '1 ton')
corvette = Car('Chevrolet', 'Corvette', 2020, '1 ton')
challenger = Car('Dodge', 'Challenger', 2019, '1 ton')
for i in range(50):
challenger.drive()
challenger.stop()
for i in range(101):
mustang.drive()
mustang.stop()
corvette.drive()
corvette.stop()
corvette.repair()
cars = [mustang, corvette, challenger]
for car in cars:
values = [
car.make,
car.model,
car.year,
car.weight,
car.needsMaintenance,
car.tripsSinceMaintenance
]
for value in values:
print(value)
print('')