# feul_efficiency.py
#   This program calculates the feul efficiency of a multi-leg journey.
# by: Scott Gordon
def main():
    print("***** Welcome to Fuel Efficiency Estimator *****")
    print("Hit enter to signal the end of the trip.\n")
    distance, fuel = 0.0, 0.0
    input_str = input("Enter gallons and miles (comma separated): ")
    while input_str != "":
        inputs = input_str.split(",")
        gallons, miles = int(inputs[0]), int(inputs[1])
        print(f"MPG for this leg: {miles/gallons:.1f}")
        distance = distance + miles
        fuel = fuel + gallons
        input_str = input("Enter gallons and miles (comma separated): ")
    print(f"You traveled a total of {distance:.1f} miles on {fuel:.1f} gallons.")
    print(f"The fuel efficiency was {distance/fuel:.1f} miles per gallon.")
if __name__ == '__main__':
    main()
Photo by sippakorn yamkasikorn on Unsplash
              
    
Top comments (0)