Here’s a Python function that calculates the cost of gas for a trip:
def calculate_gas_cost(mpg, miles, cost_per_gallon):
gallons = miles / mpg
cost = gallons * cost_per_gallon
return cost
For Trip #1, you would call the function like this:
calculate_gas_cost(25, 190, 3.62)
The cost of gas for this trip would be $27.56.
For Trip #2, you would call the function like this:
calculate_gas_cost(28, 75, 3.14)
The cost of gas for this trip would be $8.13.
For Trip #3, you would call the function like this:
calculate_gas_cost(20, 460, 3.12)
The cost of gas for this trip would be $86.88.
I hope this helps! Let me know if you have any other questions.