ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import math
print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5))
  1. A. -3 -2 -3 -2
  2. B. -3 -3 -2 -2
  3. C. -3 -2 -2 -2
  4. D. -2 -2 -2 -2

Correct answer: C. -3 -2 -2 -2

floor goes down to -3 and ceil goes up to -2. trunc and int both round toward zero, giving -2.

More Python Programming questions

Exams that ask this topic