ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(round(2.675, 2), round(2.665, 2), round(1.0049999999999999, 3), round(-2.5, 0))
  1. A. 2.67 2.67 1.005 -2.0
  2. B. 2.67 2.66 1.005 -2.0
  3. C. 2.67 2.67 1.004 -2.0
  4. D. 2.68 2.67 1.005 -3.0

Correct answer: A. 2.67 2.67 1.005 -2.0

Each literal is stored as a double, and the stored value decides the result. 2.675 and 2.665 are both just above their midpoints in binary, so both round to 2.67. Half-to-even sends -2.5 to -2.0.

More Python Programming questions

Exams that ask this topic