ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(divmod(-(10 ** 20), 7))
  1. A. (-14285714285714285714, 2)
  2. B. (-14285714285714285714, 5)
  3. C. (-14285714285714285715, 2)
  4. D. (-14285714285714285715, 5)

Correct answer: D. (-14285714285714285715, 5)

Python's // floors toward negative infinity, and % takes the sign of the divisor. 10^20 = 7 * 14285714285714285714 + 2, so -(10^20) = 7 * (-14285714285714285715) + 5, giving remainder 5.

More Python Programming questions

Exams that ask this topic