ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
print(0.1 + 0.2 - 0.3, 0.3 - 0.1 - 0.2, 1 / 49 * 49, 1 / 10 * 10)
  1. A. 5.551115123125783e-17 -2.7755575615628914e-17 0.9999999999999999 1.0
  2. B. 5.551115123125783e-17 -2.7755575615628914e-17 1.0 1.0
  3. C. 0.0 0.0 1.0 1.0
  4. D. 5.551115123125783e-17 2.7755575615628914e-17 0.9999999999999999 0.0

Correct answer: A. 5.551115123125783e-17 -2.7755575615628914e-17 0.9999999999999999 1.0

Each decimal is an approximation, so the residuals are tiny and the order of operations changes their sign. 1/49 has no exact binary form, so multiplying back by 49 can fall just below 1.

More Python Programming questions

Exams that ask this topic