ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. True True True

Floor division and modulo satisfy a == (a // b) * b + a % b for every nonzero b, so all three checks are True.

More Python Programming questions

Exams that ask this topic