# Define your function here. def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon): # edit the return statement on line 6 # enter the variable names in place of VARIABLE-NAME # Hint: miles * (gals / miles) * ($ / gals) --> $ return driven_miles * (1.0 / VARIABLE-NAME) * VARIABLE-NAME if __name__ == '__main__': #leave this statement as is. miles_per_gallon = float(input()) #leave this statement as is. dollars_per_gallon = float(input()) #leave this statement as is. # edit the next three lines replacing the correct variable names # for the VARIABLE-NAME placeholder text print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, VARIABLE-NAME, VARIABLE-NAME))) print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, VARIABLE-NAME, VARIABLE-NAME))) print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, VARIABLE-NAME, VARIABLE-NAME)))
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / VARIABLE-NAME) * VARIABLE-NAME
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, VARIABLE-NAME, VARIABLE-NAME)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, VARIABLE-NAME, VARIABLE-NAME)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, VARIABLE-NAME, VARIABLE-NAME)))
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
1) Below is your updated program where VARIABLE-NAME is updated with actual variable
2) Program does below activities
- It reads the user input for miles per gallon and dollers per gallon
- Call the function driving_cost for driven miles 10. 50. 400
- The function driving_cost
- takes input parameters like driven_miles, miles_per_gallon, dollars_per_gallon
- Calculate trhe cost of travel using formula
- return the calculated value
- Main program prints the return value from driving_cost function for 10.50 and 400 miles
3) Save program in pythoin file and run
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
# edit the return statement on line 6
# enter the variable names in place of VARIABLE-NAME
# Hint: miles * (gals / miles) * ($ / gals) --> $
return driven_miles * (1.0 / miles_per_gallon) * dollars_per_gallon
if __name__ == '__main__': #leave this statement as is.
miles_per_gallon = float(input()) #leave this statement as is.
dollars_per_gallon = float(input()) #leave this statement as is.
# edit the next three lines replacing the correct variable names
# for the VARIABLE-NAME placeholder text
print('Cost for 10 miles: {:.2f}'.format(driving_cost(10.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 50 miles: {:.2f}'.format(driving_cost(50.0, miles_per_gallon, dollars_per_gallon)))
print('Cost for 400 miles: {:.2f}'.format(driving_cost(400.0, miles_per_gallon, dollars_per_gallon)))
From Student
When i put in the code this was the output which is wrong.
Traceback (most recent call last): File "main.py", line 9, in <module> miles_per_gallon=float(input()) #leave this statement as is. EOFError: EOF when reading a line