ProgrammingHardTCS NQT · Accenture

What is printed?

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

Correct answer: B. -1 0 0 2

floor rounds toward negative infinity, so -0.5 becomes -1. ceil rounds toward positive infinity and gives 0 as an int, and trunc drops the fraction, giving 0 as well.

More Python Programming questions

Exams that ask this topic