We appreciate your visit to Problem 1 Vehicles Write a program that models two vehicles Car and Truck and can simulate driving and refueling them in the summer Both the. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
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
Thanks for taking the time to read Problem 1 Vehicles Write a program that models two vehicles Car and Truck and can simulate driving and refueling them in the summer Both the. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada