Question: 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  use Python program Output that is a decimal number can be

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!