ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import math
print(math.floor(-2.5), math.trunc(-2.5), -7.5 // 2, divmod(7.5, 2))
  1. A. -3 -2 -4.0 (3.0, 1.5)
  2. B. -2 -2 -4.0 (3.0, 1.5)
  3. C. -3 -3 -4.0 (3.0, 1.5)
  4. D. -3 -2 -3.0 (3.0, 1.5)

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

floor rounds toward minus infinity and trunc rounds toward zero. Float floor division also floors, and divmod returns the floored quotient as a float with remainder 1.5.

More Python Programming questions

Exams that ask this topic