ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(7 // 0.5, 7 % 0.5, -7 // 0.5)
  1. A. 14 0.0 -14
  2. B. 14.0 0.0 -14.0
  3. C. 14.0 1.0 -14.0
  4. D. 14.0 0.0 -15.0

Correct answer: B. 14.0 0.0 -14.0

0.5 is exact in binary, so 7 / 0.5 is exactly 14 and the remainder is 0.0. Floor division with a float operand returns a float, and -7 // 0.5 is -14.0.

More Python Programming questions

Exams that ask this topic