Question: 6 . 2 0 LAB: Driving costs - functions - AS Write a function called driving _ cost ( ) with input parameters miles _

6.20 LAB: Driving costs - functions-AS
Write a function called driving_cost() with input parameters miles_per_gallon, dollars_per_gallon, and miles_driven, that returns the dollar cost to drive those miles. All items are of type float. For example, when the function is called with the arguments (20.0,3.1599,50.0), it returns 7.89975 to the calling program, which can be used or formatted by the program, appropriately.
Write a program called car_driving_cost, which asks a user for the number of cars to process. It then, for each car, inputs the car's miles per gallon, the price of gas in dollars per gallon, and the number of driven miles (all in float). The program output the car's miles per gallon, the price of gas in dollars per gallon, the number of driven miles, and the gas price of driving the car. The program calls the function driving_cost() to compute the gas price of driving the car.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print(f'{your_value:.2f}')
Example
Enter the number of cars: 2
for car 1
Enter miles per gallon: 20
Enter Dollar amount per gallon: 3.50
Enter the number of miles the car was driven: 100
Miles per gallon: 20.00
Dollars per gallon: $3.50
Miles driven: 100.00
Driving cost: $17.50
for car 2
Enter miles per gallon: 15
Enter Dollar amount per gallon: 3.99
Enter the number of miles the car was driven: 112
Miles per gallon: 15.00
Dollars per gallon: $3.99
Miles driven: 112.00
Driving cost: $29.79
Enjoy your moments!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!