146k views
5 votes
Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.

Ex: If the input is 20.0 3.1599
The output is: 1.57995 7.89975 63.198

1 Answer

8 votes

Answer:

Step-by-step explanation:

The following is written in Python. It is a function that takes in two parameters called miles for miles/gallon and gasCost for gas dollars/gallon. Then it creates three variables for each number of miles used (10,50,400) and calculates the total cost for each. Finally, it returns all three costs to the user

def mileage(miles, gasCost):

tenMiles = (10.00 / miles) * gasCost

fiftyMiles = (50.00 / miles) * gasCost

fourHundredMiles = (400.00 / miles) * gasCost

return tenMiles, fiftyMiles, fourHundredMiles

User Omilus
by
4.1k points