Answer:
In Python:
gals= float(input("Enter the gallons used (-1 to end): "))
miles = float(input("Enter the miles driven: "))
mileage = 0.0
count = 0
while not (gals == -1):
count += 1
mileage +=(miles/gals)
print("The miles/gallon for this tank was "+str(round(miles/gals,6)))
gals= float(input("Enter the gallons used (-1 to end): "))
miles = float(input("Enter the miles driven: "))
print("The overall average miles/gallon was "+str(round(mileage/count,6)))
Step-by-step explanation:
#This prompts the user for the number of gallons used
gals= float(input("Enter the gallons used (-1 to end): "))
#This prompts the user for miles driven
miles = float(input("Miles driven: "))
#This initializes the mileage to 0
mileage = 0.0
#This initializes the count of vehicles to 0
count = 0
#The following is repeated until input for gallons is -1
while not (gals == -1):
#The count of vehicles is increased by 1
count += 1
#The total mileage for all cars is calculated
mileage +=(miles/gals)
#This prints the mileage for that particular vehicle
print("The miles/gallon for this tank was "+str(round(miles/gals,6)))
#This prompts the user for the number of gallons used
gals= float(input("Enter the gallons used (-1 to end): "))
#This prompts the user for miles driven
miles = float(input("Miles driven: "))
#This calculates and prints the overall average mileage
print("The overall average miles/gallon was "+str(round(mileage/count,6)))