ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(7.5 // 2, 7.5 % 2, -7.5 // 2, divmod(7.5, -2))
  1. A. 3.0 1.5 -4.0 (-4.0, -0.5)
  2. B. 3.0 1.5 -3.0 (-3.0, 1.5)
  3. C. 3.0 1.5 -4.0 (-3.0, -0.5)
  4. D. 3 1.5 -4 (-4.0, -0.5)

Correct answer: A. 3.0 1.5 -4.0 (-4.0, -0.5)

Float floor division and modulo follow the same sign rules as ints, and the results are floats. divmod(7.5, -2) gives quotient -4.0 and remainder -0.5, since -4.0 * -2 + -0.5 = 7.5.

More Python Programming questions

Exams that ask this topic