ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
import math
print(int(-0.5), int(-1.9), math.floor(-1.1), round(-1.5))
  1. A. 0 -1 -2 -2
  2. B. 0 -2 -2 -2
  3. C. -1 -1 -2 -2
  4. D. 0 -1 -1 -2

Correct answer: A. 0 -1 -2 -2

int() truncates toward zero, so -0.5 becomes 0 and -1.9 becomes -1. floor rounds toward negative infinity, giving -2, and round(-1.5) rounds to the even neighbour, -2.

More Python Programming questions

Exams that ask this topic