ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: D. -1 0 0 3

floor rounds down to -1, while ceil of -0.5 is the integer 0 because ints have no negative zero. The literal 2.999999999999999999 is the double 3.0, so floor gives 3.

More Python Programming questions

Exams that ask this topic