Answer:
Program written in Python:
Please note that -> is used for indentation purpose
count = int(input("Number of vehicles: "))
totaldist = 0; totalgall = 0
for i in range(count):
-> gallon = int(input("Gallons: "))
-> distance = int(input("Kilometers Travelled: "))
-> totaldist = totaldist + distance
-> totalgall = totalgall + gallon
-> rate = distance/gallon
-> print("Kilometer/Gallon: "+str(rate))
print("Miles/Gallon: "+str(totaldist * 1.609/totalgall))
Step-by-step explanation:
The program uses loop to ask for distance and gallons used by each vehicles.
At the end of the loop, the program divided the total distance by all vehicles in miles by total gallon user by all vehicles
[This line prompts user for number of vehicles]
count = int(input("Number of vehicles: "))
[This line initialised total distance and total gallon to 0]
totaldist = 0; totalgall = 0
[This iterates through number of vehicles]
for i in range(count):
[This prompts user for gallons used]
gallon = int(input("Gallons: "))
[This prompts user for distance traveled]
distance = int(input("Kilometers Travelled: "))
[This calculates total distance]
totaldist = totaldist + distance
[This calculates total gallons]
totalgall = totalgall + gallon
[This calculates the rate by each vehicles: kilometres per gallon]
rate = distance/gallon
[This prints the calculated rate]
print("Kilometer/Gallon: "+str(rate))
[The iteration ends here]
[This calculates and prints the rate of all vehicles. The rate is calculated by dividing total distance in miles by total gallons used]
print("Miles/Gallon: "+str(totaldist * 1.609/totalgall))