I need help with this in python programming The fuel efficiency (miles per gallo
ID: 3712562 • Letter: I
Question
I need help with this in python programming
The fuel efficiency (miles per gallon (MPG)) of an automobile driven on a highway can be calculated with the following formula:
???? = 71.7 ?? (2 + 0.0192 ? ??)?4.5 + ??(?5.1??) ? 1
Where:
- s is the speed of the car in miles per hour.
- e is the mathematical constant known as the Euler's number
Given this formula, you can now figure out how much gasoline is needed for a particular long distance trip. A program that asks the user to enter data for the average speed driven during a trip (in miles per hour (MPH)), the distance traveled during the trip (in miles) and the cost of gasoline (dollars per gallon). The output of the program should print the fuel efficiency (FE), total number of gallons consumed during the trip, and the total cost of the consumed gasoline. When printing the results, you can round the values by using the function round(someValue, 2) – that way the results will be displayed with 2 decimal places.
Explanation / Answer
from __future__ import division
from math import exp
def fuel_efficiency(s):
return 71.7 * s * (2 + 0.0192 * s) * (-4.5) + exp(1) * (-5.1 * s) - 1;
def get_fuel_consumed(distance, fe):
return distance/fe
def get_total_fuel_cost(cost_per_gallon, fuel_consumed):
return cost_per_gallon*fuel_consumed
s = float(input("Enter average speed driven during trip (Miles/Hour): "))
distance = float(input("Enter distance travelled during trip (miles): "))
cost_per_gallon = float(input("Enter cost of gasoline (dollars per gallon): "))
fe = fuel_efficiency(s)
fuel_consumed = get_fuel_consumed(distance, fe)
cost = get_total_fuel_cost(cost_per_gallon, fuel_consumed)
print("Fuel efficiency: %.2f Gallons consumed: %.2f Total cost of gasoline: %.2f" % (fe, fuel_consumed, cost))
# copy pastable code link: https://paste.ee/p/54HU6