Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use Python program Output that is a decimal number can be formatted so that the number is rounded to a specified number of decimal places.

use Python program image text in transcribed
Output that is a decimal number can be formatted so that the number is rounded to a specified number of decimal places. For example, in the TravelPlanner program we might decide that the travel time required should be printed to only two decimal places. We would change the second print statement as follows: print ("At", speed, "mph, it will take ") travel", print("%5.2f" % time, "hours to distance, "miles.") The "85 . 2f" % is a formatting directive for printing the numerical value time that follows it. The "f" part says the next variable is to be converted (if necessary) to type float. The 5.2 says to print the resulting decimal value using 5 columns (including the decimal point) and rounded to 2 decimal places. The sample result would be Enter your speed in mph: 58 Enter your distance in miles: 657.5 At 58 mph, it will take 11.34 hours to travel 657.5 miles. If this were done in one print statement instead of two, the formatting directive could be included as the end of the literal string preceding the variable time. Write two Python print statements to generate the following output, assuming that density is a type double variable with the value 63.78: The current density is 63.8 to within one decimal place

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions