My library > CMPSC 8: Introduction to Computer Science h. > = zyBooks 2.11: LAB: Computing driving costs E zyBooks catalog 2 Help/FAQ Hannah Shakouri Learning Objective: Students will practice using floating numbers and how to print them using.format to produce a certain number of digits after the decimal point. Lab Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('(:.2f} {:.2f} {:.2f}'.format (your_valuel, your value2, your_value3)) Ex: If the input is: 20.0 3.1599 Then the output is: 3.16 11.85 79.00 How did we determine this? Well, if you drive at 20 miles/gallon (that was the user's first input), then you will use 1 gallon to cover 20 miles, 3.75 gallons to cover 75 miles, and 25 gallons to drive 500 miles. Since the user's second input was the cost of gas (dollars/gallon), you can compute how much it would cost you to drive each of these distances (miles * (gallon/miles) * (dollars/gallon) -> dollars). We recommend writing out this calculation by hand to allow you to track each part of the equation Important: notice that you need to take only two values as input, which means that you can store the distances for 20 miles, 75 miles, and 500 miles directly in your program as three variables. Note: Real per-mile cost would also include maintenance and depreciation. LAB 2.11.1: LAB: Computing driving costs 0/10 АCTIVITY

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question
100%

* I should use input () and .format in my code.

* I should enter my two inputs in the box I have marked. 

= zyBooks
My library > CMPSC 8: Introduction to Computer Science h. >
2.11: LAB: Computing driving costs
E zyBooks catalog
?Help/FAQ 8 Hannah Shakouri
Learning Objective:
Students will practice using floating numbers and how to print them using.format to produce a certain number of digits after the decimal
point.
Lab
Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20
miles, 75 miles, and 500 miles.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:. 2f} {:.2f} {:.2f}'.format(your_valuel, your_value2, your_value3))
Ex: If the input is:
20.0
3.1599
Then the output is:
3.16 11.85 79.00
How did we determine this? Well, if you drive at 20 miles/gallon (that was the user's first input), then you will use 1 gallon to cover 20 miles,
3.75 gallons to cover 75 miles, and 25 gallons to drive 500 miles. Since the user's second input was the cost of gas (dollars/gallon), you can
compute how much it would cost you to drive each of these distances (miles * (gallon/miles) * (dollars/gallon) -> dollars).
We recommend writing out this calculation by hand to allow you to track each part of the equation
Important: notice that you need to take only two values as input, which means that you can store the distances for 20 miles, 75 miles, and
500 miles directly in your program as three variables.
Note: Real per-mile cost would also include maintenance and depreciation.
354684.2266598.qx3zqy7
LAB
2.11.1: LAB: Computing driving costs
0/10
ACTIVITY
Transcribed Image Text:= zyBooks My library > CMPSC 8: Introduction to Computer Science h. > 2.11: LAB: Computing driving costs E zyBooks catalog ?Help/FAQ 8 Hannah Shakouri Learning Objective: Students will practice using floating numbers and how to print them using.format to produce a certain number of digits after the decimal point. Lab Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:. 2f} {:.2f} {:.2f}'.format(your_valuel, your_value2, your_value3)) Ex: If the input is: 20.0 3.1599 Then the output is: 3.16 11.85 79.00 How did we determine this? Well, if you drive at 20 miles/gallon (that was the user's first input), then you will use 1 gallon to cover 20 miles, 3.75 gallons to cover 75 miles, and 25 gallons to drive 500 miles. Since the user's second input was the cost of gas (dollars/gallon), you can compute how much it would cost you to drive each of these distances (miles * (gallon/miles) * (dollars/gallon) -> dollars). We recommend writing out this calculation by hand to allow you to track each part of the equation Important: notice that you need to take only two values as input, which means that you can store the distances for 20 miles, 75 miles, and 500 miles directly in your program as three variables. Note: Real per-mile cost would also include maintenance and depreciation. 354684.2266598.qx3zqy7 LAB 2.11.1: LAB: Computing driving costs 0/10 ACTIVITY
2.11: LAB: Computing driving costs
500 miles directly in your program as three variables.
Note: Real per-mile cost would also include maintenance and depreciation.
354684.2266598.qx3zqy7
LAB
2.11.1: LAB: Computing driving costs
0/10
ACTIVITY
main.py
Load default template...
1
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
Develop mode
Submit mode
SECC.
hox.
Enter program input (optional)
If your code requires input values, provide them here.
input (from above) =
main.py
(Your program)
→ Output (shown below)
Transcribed Image Text:2.11: LAB: Computing driving costs 500 miles directly in your program as three variables. Note: Real per-mile cost would also include maintenance and depreciation. 354684.2266598.qx3zqy7 LAB 2.11.1: LAB: Computing driving costs 0/10 ACTIVITY main.py Load default template... 1 Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the Develop mode Submit mode SECC. hox. Enter program input (optional) If your code requires input values, provide them here. input (from above) = main.py (Your program) → Output (shown below)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning