Question: 5 . 4 0 LAB: Driving costs - functions Write a function driving _ cost ( ) that has 3 parametersmiles _ per _ gallon,
LAB: Driving costs functions
Write a function drivingcost that
has parametersmilespergallon, dollarspergallon, and milesdriven, and
that returns the cost in dollars to drive those miles rounded to decimal places.
Then inside if main:
get the inputs for miles per gallon, dollars, and miles driven
call the function passing paramters
print the returned value
All items are of type float.
Ex: If the input is:
Enter miles per gallon:
Enter dollars per gallon:
Enter miles to drive:
the return value of the function is:
but the output is:
because we want dollars and cents as an answer.
Ex If the input is:
Enter miles perfallon:
Enter dollars per gallon:
Enter miles to drive:
the return value of the function is:
but the output is:
Output the floatingpoint 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 drivingcostmilespergallon, dollarspergallon, milesdriven
LAB
ACTIVITY
: LAB: Driving costs functions
main.py
Load default template..
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
