ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(divmod(-1, 10), divmod(1, -10), -1 % 10)
  1. A. (-1, 9) (-1, 8) 9
  2. B. (0, 9) (0, -9) -1
  3. C. (-1, 9) (-1, -9) 9
  4. D. (0, -1) (0, 1) 9

Correct answer: C. (-1, 9) (-1, -9) 9

Floor division gives -1 for -1 // 10 with remainder 9. For 1 // -10 the quotient is -1 and the remainder is 1 + (-10) = -9. -1 % 10 is 9.

More Python Programming questions

Exams that ask this topic