ProgrammingVery hardTCS NQT · Infosys

What is printed?

What is printed?
print(round(1.005, 2), round(0.285, 2), round(1.45, 1))
  1. A. 1.0 0.28 1.4
  2. B. 1.01 0.29 1.5
  3. C. 1.0 0.29 1.5
  4. D. 1.01 0.28 1.4

Correct answer: A. 1.0 0.28 1.4

Each decimal literal is stored as a binary double slightly below the halfway point (1.00499..., 0.28499..., 1.44999...). So round() goes down in all three cases, and no decimal intuition applies.

More Python Programming questions

Exams that ask this topic