ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. -4.0 0.5

Float floor division also floors toward negative infinity: -7.5 / 2 = -3.75 floors to -4.0. The remainder takes the sign of the divisor, so -7.5 - (-4.0 * 2) = 0.5.

More Python Programming questions

Exams that ask this topic