Question: 5 . 4 0 LAB: Driving costs - functions Write a function driving _ cost ( ) that has 3 parametersmiles _ per _ gallon,

5.40 LAB: Driving costs - functions
Write a function driving_cost () that
has 3 parametersmiles_per_gallon, dollars_per_gallon, and miles_driven, and
that returns the cost in dollars to drive those miles rounded to 2 decimal places.
Then inside if _== main_':
get the 3 inputs for miles per gallon, dollars, and miles driven
call the function passing 3 paramters
print the returned value
All items are of type float.
Ex: If the input is:
Enter miles per gallon: 20.0
Enter dollars per gallon: 3.1599
Enter miles to drive: 50.0
the return value of the function is:
7.89975
but the output is:
7.90
because we want dollars and cents as an answer.
Ex. If the input is:
Enter miles perfallon: 18.0
Enter dollars per gallon: 4.599
Enter miles to drive: 210
the return value of the function is:
53.65500
but the output is:
53.66
Output the floating-point value with two digits after the decimal point, which can be achieved using a format specifier in your print statement (%f)
Your pragram must define and cll a function:
def driving_cost(miles_per_gallon, dollars_per_gallon, miles_driven)
539078.3140466.93z9y7
LAB
ACTIVITY
5.40.1: LAB: Driving costs - functions
410
main.py
Load default template..
1
 5.40 LAB: Driving costs - functions Write a function driving_cost ()

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 Databases Questions!