ProgrammingVery hardTCS NQT · Infosys

What is printed?

What is printed?
print('%.2f' % 1.005, '%.2f' % 1.015, '%.2f' % 1.025, '%.1f' % 0.25)
  1. A. 1.01 1.01 1.03 0.3
  2. B. 1.00 1.02 1.03 0.2
  3. C. 1.00 1.01 1.03 0.2
  4. D. 1.00 1.01 1.02 0.2

Correct answer: D. 1.00 1.01 1.02 0.2

Each decimal is stored just below or at the halfway point, and 0.25 is exact, so it rounds half to even. That gives 1.00, 1.01 and 1.02, and 0.2 for the last one.

More Python Programming questions

Exams that ask this topic