# 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)))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

 

 

# 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)))

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

 

 

 

 

 

 

 

 

 

Explanation

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

arrow_forward
Program

# 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)))

arrow_forward
Test Output

 

 

Program

# 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)))

arrow_forward
Test Output

 

 

 

 

 

 

 

 

 

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

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education