ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: B. True True 1 -2

-5 % 3 is 1 and 5 % -3 is -1, both with the divisor's sign. -5 // -3 floors 1.67 to 1, while 5 // -3 floors -1.67 to -2.

More Python Programming questions

Exams that ask this topic