ProgrammingHardGATE CS · Product-company placement

What is printed?

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

Correct answer: A. -3 -2 -2 -2 -2 -3.0

floor goes down (-3), ceil up (-2), trunc and int() go toward zero (-2), round uses banker's rounding (-2.5 -> -2, the even neighbour), and // 1 floors but keeps the float type (-3.0).

More Python Programming questions

Exams that ask this topic