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
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
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.
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
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning