ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: C. True True False

The identity a == (a // b) * b + a % b holds for any sign. The unary minus in -10 ** 18 applies after the power, so -10 ** 18 % 7 is 6 while (-10) ** 18 % 7 is 1.

More Python Programming questions

Exams that ask this topic