ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. True False

Above 2**53 doubles are spaced by 2, so 10**16 + 1 rounds to 10**16 as a float. The int comparison is exact, so 10**16 + 1 is not equal to the float.

More Python Programming questions

Exams that ask this topic