ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(format(0.5, '.0f'), format(1.5, '.0f'), format(2.5, '.0f'), format(-0.5, '.0f'))
  1. A. 0 2 3 -1
  2. B. 0 1 2 -0
  3. C. 0 2 2 1
  4. D. 0 2 2 -0

Correct answer: D. 0 2 2 -0

Half-to-even rounding sends 0.5 to 0, 1.5 to 2 and 2.5 to 2. -0.5 rounds to a negative zero, and the format keeps its minus sign.

More Python Programming questions

Exams that ask this topic