Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
Check Mark
Still need help?
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
by Bartleby Expert
SEE SOLUTION
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
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education