ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: B. True True -7

For any sign, a == (a // b) * b + a % b holds in Python, so the last value is -4 * 2 + 1 = -7. Languages that truncate toward zero would give -6 + (-1) and break the identity.

More Python Programming questions

Exams that ask this topic