Question: Write a program that computes the fuel efficiency of a multi-leg journey. (Refer to exercise 9 of Chapter 8.) A. Prompt for the starting odometer

Write a program that computes the fuel efficiency of a multi-leg journey. (Refer to exercise 9 of Chapter 8.)

A. Prompt for the starting odometer reading.

B.Get information about a series of legs. i.For each leg, the user enters the current odometer reading and the amount of gas used (separate by a space). ii.The user signals the end of the trip with a blank line.

C.The program should print or display the miles per gallon (MPG) achieved on each leg and the total MPG for the trip.

This is what I have so far and I can not get it to work, please help.

def main():

initial_reading = input("Please enter the starting odometer reading:")

initial_reading = float(initial_reading)

total_distance, total_gallon = 0.0, 0.0

distanceGas = input("Please enter the current odometer reading and the amount of gas used:")

while distanceGas!="":

distance, gallon = distanceGas.split()

gallon = float(gallon)

distance = float(distance)

actual_distance = distance - initial_reading

initial_reading = distance

print("MPG for this leg is:{0:0.2f}".format(actual_distance/gallon))

total_distance = total_distace + actual_distance

total_gallon = total_gallon + gallon

distanceGas = input("Please enter the current odometer reading and the amount of gas used:")

total_MPG = total_distance/total_gallon

print("Total MPG for the trip is: {0:0.2f}".format(total_MPG))

main()

Screenshot also attached:

Write a program that computes the fuel efficiency of a multi-leg journey.

(Refer to exercise 9 of Chapter 8.) A. Prompt for the starting

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!