ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(10 % 3.5, -10 % 3.5, 10 // 3.5, round(-1.5), round(0.5) + round(1.5))
  1. A. 3.0 0.5 2.0 -1 2
  2. B. 3.0 0.5 2.0 -2 1
  3. C. 2.0 0.5 2.0 -2 2
  4. D. 3.0 0.5 2.0 -2 2

Correct answer: D. 3.0 0.5 2.0 -2 2

The % result takes the sign of the divisor, so -10 % 3.5 is 0.5, and 10 // 3.5 is 2.0. round uses half-to-even, so round(-1.5) is -2, and round(0.5) + round(1.5) is 0 + 2.

More Python Programming questions

Exams that ask this topic