94.4k views
0 votes
2.13 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3)) Ex: If the input is: 20.0

1 Answer

0 votes

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

gallon_used = driven_miles / miles_per_gallon

cost = gallon_used * dollars_per_gallon

return cost

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Step-by-step explanation:

User Eawenden
by
5.5k points