ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print('%.2e' % 0, '%.1f' % 2.25, '%.1f' % 2.35, '%5.1f|' % -0.04)
  1. A. 0.00e+00 2.2 2.4 -0.0|
  2. B. 0.00e+00 2.3 2.4 -0.0|
  3. C. 0.00e+00 2.2 2.3 -0.0|
  4. D. 0.00e+00 2.2 2.4 -0.00|

Correct answer: A. 0.00e+00 2.2 2.4 -0.0|

2.25 is exactly halfway, so %.1f rounds it to the even 2.2. 2.35 is stored slightly above the midpoint and rounds to 2.4. The width of 5 pads -0.0 with one space on the left.

More Python Programming questions

Exams that ask this topic