ProgrammingModeratePython · GATE DA

What is printed?

What is printed?
print(7 // 2, -7 // 2, 7 % -3, divmod(-7, 2), 2 ** -1)
  1. A. 3 -3 1 (-3, -1) 0.5
  2. B. 3 -4 1 (-4, 1) 0
  3. C. 3 -4 -2 (-3, -1) 0.5
  4. D. 3 -4 -2 (-4, 1) 0.5

Correct answer: D. 3 -4 -2 (-4, 1) 0.5

// floors, so -7//2 = -4; the % result takes the sign of the divisor (7 % -3 = -2); divmod(-7, 2) = (-4, 1); 2**-1 is the float 0.5.

More Python Programming questions

Exams that ask this topic