-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_01_01.py
More file actions
31 lines (26 loc) · 1.11 KB
/
Task_01_01.py
File metadata and controls
31 lines (26 loc) · 1.11 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
"""
A vehicle is identified by its mileage (in kms per litre) and fuel left (in litres) in the vehicle. From the fuel left, 5 litres will always be considered as reserve fuel. At any point of time, the driver of the vehicle may want to know:
the maximum distance that can be covered without using the reserve fuel
how many kms he/she has already travelled based on the initial fuel the vehicle had
"""
#!/python3
class Vehicle:
def __init__(self):
self.mileage=None
self.fuel_left=None
def identify_distance_travelled(self,initial_fuel):
distance_travelled=(initial_fuel-self.fuel_left)* self.mileage
return distance_travelled
def identify_distance_that_can_be_travelled(self):
initial_fuel=15
distance_travelled=self.identify_distance_travelled(initial_fuel)
if self.fuel_left>5:
return (initial_fuel-5)*self.mileage- distance_travelled
else:
return 0
t = Vehicle()
t.mileage = 30
t.fuel_left =10
print(t.mileage)
print(t.identify_distance_travelled(20))
print(t.identify_distance_that_can_be_travelled())