Answer :
A program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in the summer is given.
How to depict the program
class Car:
def __init__(self, fuel_quantity, liters_per_km):
self.fuel_quantity = fuel_quantity
self.liters_per_km = liters_per_km
def drive(self, distance):
fuel_required = distance * (self.liters_per_km + 0.9) # increased consumption with AC
if fuel_required <= self.fuel_quantity:
self.fuel_quantity -= fuel_required
return f"Car travelled {distance:.2f} km"
else:
return "Car needs refueling"
def refuel(self, liters):
self.fuel_quantity += liters
def __str__(self):
return f"Car: {self.fuel_quantity:.2f}"
class Truck:
def __init__(self, fuel_quantity, liters_per_km):
self.fuel_quantity = fuel_quantity
self.liters_per_km = liters_per_km
def drive(self, distance):
fuel_required = distance * (self.liters_per_km + 1.6) # increased consumption with AC
if fuel_required <= self.fuel_quantity:
self.fuel_quantity -= fuel_required
return f"Truck travelled {distance:.2f} km"
else:
return "Truck needs refueling"
def refuel(self, liters):
self.fuel_quantity += liters * 0.95 # 95% of the given fuel due to the hole in the tank
def __str__(self):
return f"Truck: {self.fuel_quantity:.2f}"
car_info = input().split()
car = Car(float(car_info[1]), float(car_info[2]))
truck_info = input().split()
truck = Truck(float(truck_info[1]), float(truck_info[2]))
n = int(input())
for _ in range(n):
command = input().split()
if command[0] == "Drive":
if command[1] == "Car":
result = car.drive(float(command[2]))
print(result)
elif command[1] == "Truck":
result = truck.drive(float(command[2]))
print(result)
elif command[0] == "Refuel":
if command[1] == "Car":
car.refuel(float(command[2]))
elif command[1] == "Truck":
truck.refuel(float(command[2]))
print(car)
print(truck)
Learn more about program on
https://brainly.com/question/26642771
#SPJ1