ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
x = 5
print(x // 2 * 2 == x, x / 2 * 2 == x, 5 / 2 == 2.5, 5 // 2.0 == 2)
  1. A. False True False True
  2. B. True True True True
  3. C. False True True True
  4. D. False False True True

Correct answer: C. False True True True

5 // 2 * 2 is 4, so the first comparison is False. Division by 2 is exact in binary here, so 5 / 2 * 2 is 5.0 and equals x. 5 // 2.0 is 2.0, which equals 2.

More Python Programming questions

Exams that ask this topic