What will be the output of the following Python expression if x=56.236? print(“%.2f”%x)
What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a. 56.236
b. 56.23
c. 56.0000
d. 56.24
1 Answers
d. 56.24
Explanation: The expression shown above rounds off the given number to the number of decimal places specified. Since the expression given specifies rounding off to two decimal places, the output of this expression will be 56.24. Had the value been x=56.234 (last digit being any number less than 5), the output would have been 56.23.