Thank you for visiting 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 is designed to guide you through key points and clear explanations related to the topic at hand. We aim to make your learning experience smooth, insightful, and informative. Dive in and discover the answers you're looking for!
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
Thank you for reading the article 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 information provided is useful and helps you understand this topic better. Feel free to explore more helpful content on our website!
- You are operating a recreational vessel less than 39 4 feet long on federally controlled waters Which of the following is a legal sound device
- Which step should a food worker complete to prevent cross contact when preparing and serving an allergen free meal A Clean and sanitize all surfaces
- For one month Siera calculated her hometown s average high temperature in degrees Fahrenheit She wants to convert that temperature from degrees Fahrenheit to degrees
Rewritten by : Jeany