DEV Community

Cover image for Fuel Efficiency Estimator
Scott Gordon
Scott Gordon

Posted on

1

Fuel Efficiency Estimator

# 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()
Enter fullscreen mode Exit fullscreen mode

Photo by sippakorn yamkasikorn on Unsplash

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay