Answer:
The Following are the code to this question:
def cost(miles, milesPerGallon, dollarsPerGallon):##defining a method cost that accepts three parameter
return miles / milesPerGallon * dollarsPerGallon# calculate cost and return it value
milesPerGallon = float(input('Enter miles/Gallon value: '))#defining variable milesPerGallon for user input
dollarsPerGallon = float(input('Enter dollars/ Gallon value: '))#defining variable dollarsPerGallon for user input
print('{:.5f}'.format(cost(10, milesPerGallon, dollarsPerGallon)))#call method and print its value
print('{:.5f}'.format(cost(50, milesPerGallon, dollarsPerGallon)))#call method and print its value
print('{:.3f}'.format(cost(400, milesPerGallon, dollarsPerGallon)))#call method and print its value
Output:
Enter miles/Gallon value: 20.0
Enter dollars/ Gallon value: 3.1599
1.57995
7.89975
63.198
Explanation:
In the above-given code, a method "cost" is defined, that accepts three value "miles, milesPerGallon, and dollarsPerGallon" in its parameter, and use the return keyword for calculating and return its value.
In the next step, two variable "milesPerGallon, and dollarsPerGallon" is declared, that use the input method with float keyword for input floating-point value.
After input value, it uses a print method with different miles values, which are "10,50, and 400", and input value to pass in cost method to call and print its return value.