ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)
  1. A. 2.0 -2 True True
  2. B. 2 -2 True True
  3. C. 2.0 -3 True True
  4. D. 2.0 -2 False True

Correct answer: A. 2.0 -2 True True

round with ndigits=0 on a float returns a float, so 1.5 becomes 2.0. Without ndigits round returns an int, and -2.5 rounds to the even -2. The float 2.0 equals the int 2.

More Python Programming questions

Exams that ask this topic