ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(divmod(7, 2), divmod(-7, 2), divmod(7.5, 2))
  1. A. (3, 1) (-4, 1) (3, 1.5)
  2. B. (3.5, 1) (-4, 1) (3.0, 1.5)
  3. C. (3, 1) (-4, 1) (3.0, 1.5)
  4. D. (3, 1) (-3, -1) (3.0, 1.5)

Correct answer: C. (3, 1) (-4, 1) (3.0, 1.5)

divmod uses floor division, so -7 divided by 2 gives -4 with remainder 1. With a float argument, the quotient is returned as a float, 3.0.

More Python Programming questions

Exams that ask this topic