ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: C. True False -3 -2.5

10 % 4 is 2. With a positive divisor, -10 % 4 is 2 as well, because the result takes the divisor's sign, so the second check is True and the remainder is not -2. Floor division of 10 by -4 is -3, and 10 / -4 is -2.5.

More Python Programming questions

Exams that ask this topic