ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(5 / 2, 5 // 2, -5 / 2, -5 // 2)
  1. A. 2.0 2 -2.0 -3
  2. B. 2.5 2 -2 -3
  3. C. 2.5 2 -2.5 -3
  4. D. 2.5 2 -2.5 -2

Correct answer: C. 2.5 2 -2.5 -3

/ always gives a float. // floors toward negative infinity, so -5 // 2 is -3, not -2 as truncation would give.

More Python Programming questions

Exams that ask this topic