ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(7 // 0.5, 7 % 0.5, 0.5 * 7 // 1, 1e308 * 10 == float('inf'))
  1. A. 14 0 3 True
  2. B. 14.0 0.5 3.0 True
  3. C. 14.0 0.0 3.0 True
  4. D. 14.0 0.0 3.5 True

Correct answer: C. 14.0 0.0 3.0 True

Floor division with a float returns a float, so 7 // 0.5 is 14.0. 7 % 0.5 is exactly 0.0, and 0.5 * 7 is 3.5, which floors to 3.0. Overflowing a float multiplication gives infinity.

More Python Programming questions

Exams that ask this topic