ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
x = 10 ** 16
print(float(x) == x, float(x + 1) == x, x + 1.0 == x, (x + 1) - x)
  1. A. True True True 1
  2. B. True False True 1
  3. C. True True False 1
  4. D. True True True 0

Correct answer: A. True True True 1

10**16 is exact in a double, so the first comparison is True. float(x + 1) rounds to the even neighbour 10**16, and x + 1.0 also rounds back to 10**16. The integer subtraction is exact, giving 1.

More Python Programming questions

Exams that ask this topic