Answer:
#program in Python.
#function to calculate driving cost
def driving_cost(d_miles, m_per_gallon, doll_per_gallon):
#calculate cost and return the value
return (d_miles / m_per_gallon) * doll_per_gallon
#read the miles per gallon
m_per_gallon = float(input("Enter car's miles/gallon:"))
#read dollars per gallon
doll_per_gallon = float(input("Enter gas dollars/gallon:"))
#call function to find cost for 10 miles
print('%0.2f' % driving_cost(10, m_per_gallon, doll_per_gallon))
#call function to find cost for 50 miles
print('%0.2f' % driving_cost(50, m_per_gallon, doll_per_gallon))
#call function to find cost for 400 miles
print('%0.2f' % driving_cost(400, m_per_gallon, doll_per_gallon))
Step-by-step explanation:
Read the value of miles per gallon and assign it to variable "m_per_gallon". Then read dollars per gallon from user and assign it to variable "doll_per_gallon". Call the function driving_cost() with parameter miles, m_per_gallon and doll_per_gallon. This function will find the cost of driving and return the cost.Call function for 10, 50 and 400 miles.
Output:
Enter car's miles/gallon:20
Enter gas dollars/gallon:3.1599
1.58
7.90
63.20