I'm getting an error on the output. How do I get it to print: The gas cost for 10 miles is $1.58 The gas cost for 50 miles is $7.90 The gas cost for 400 miles is $63.2
I'm getting an error on the output. How do I get it to print: The gas cost for 10 miles is $1.58 The gas cost for 50 miles is $7.90 The gas cost for 400 miles is $63.2
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
Related questions
Question
I'm getting an error on the output. How do I get it to print:
The gas cost for 10 miles is $1.58
The gas cost for 50 miles is $7.90
The gas cost for 400 miles is $63.20

Transcribed Image Text:### Programming Exercise: Calculating Gas Costs
#### Objectives:
- Create a function to match the specifications.
- Use floating-point value division.
- Acquire user input, call the custom function, and produce the desired output using a `format` function for specified precision.
#### Instructions:
Driving is expensive. Write a program using a car's miles/gallon and gas dollars/gallon (both floats) as input to calculate and output the gas cost for driving 10 miles, 50 miles, and 400 miles.
Ensure that each floating-point value is displayed with two digits after the decimal point. This can be achieved using the following code:
```python
print('{:.2f}'.format(your_value))
```
**Example Input:**
```
20.0
3.1599
```
**Expected Output:**
```
The gas cost for 10 miles is $1.58
The gas cost for 50 miles is $7.90
The gas cost for 400 miles is $63.20
```
Your program should define and call the `driving_cost()` function. This function takes three input parameters: `driven_miles`, `miles_per_gallon`, and `dollars_per_gallon`. It calculates and returns the dollar cost for driving the specified miles.
**Example Function Call:**
Implement the function with the correct logic to fulfill the above requirements.

Transcribed Image Text:### Driving Costs - Functions
#### Function Execution Example:
```plaintext
50 20.0 3.1599
```
The function returns:
```plaintext
7.89975
```
#### Function Definition:
```python
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon)
```
Your program should call the function three times to determine the gas cost for 10 miles, 50 miles, and 400 miles.
**Hint:** To calculate how many gallons I will spend to drive 1 mile I will divide 1 by a car’s miles/gallon parameter.
**Note:** Pay attention to the distinction of what the function expects and is supposed to do versus what the program needs to collect and do. In this lab, the function has 3 parameters, whereas the program collects only 2 input values because the miles are already pre-determined (i.e., hard-coded) inside of its code.
---
#### Main Activity Code:
```python
# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
return (driven_miles/miles_per_gallon)*dollars_per_gallon
if __name__ == '__main__':
# Type your code here.
miles_per_gallon = float(input())
dollars_per_gallon = float(input())
print('{:.2f}'.format(driving_cost(10, miles_per_gallon, dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(50, miles_per_gallon, dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(400, miles_per_gallon, dollars_per_gallon)))
```
This code snippet is part of a lab activity designed to teach students how to work with functions in Python. The main task is to calculate the cost of driving different distances based on input values for miles per gallon and dollars per gallon.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education