52.3k views
1 vote
9.2.2: Output formatting: Printing a maximum number of digits. Write a single statement that prints outsideTemperature with 4 digits. End with newline. Sample output with input 103.45632: 103.5

User Iwazovsky
by
5.7k points

1 Answer

5 votes

Answer:

The single print statement that does the required in python is:

print("%.4g" % outsideTemperature)

Step-by-step explanation:

The full program is as follows:

The first line prompts user for input

outsideTemperature = float(input("Outside Temperature: "))

To print significant figures, we make use of g formats. And this is implemented as follows:

print("%.4g" % outsideTemperature)

The above prints 4 significant digits of outsideTemperature

For other significant figures, simply change the 4 to another number

User Albertamg
by
5.4k points