ProgrammingVery hardWipro · Accenture · Capgemini pattern

What does the following Python 3 code print? print(2 ** 10, 2 ** 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)

  1. A. 1024 1.41 3 -3 1 -1
  2. B. 1024 1.4142135623730951 3 -4 1 -2
  3. C. 1024 1.4142135623730951 3 -4 1 2
  4. D. 1024 1.4142135623730951 3 -3 1 1

Correct answer: C. 1024 1.4142135623730951 3 -4 1 2

Floor division rounds toward negative infinity, so -10//3 is -4 (not -3); the modulo result always takes the sign of the divisor, so -10 % 3 is 2.

More Python Programming questions

Exams that ask this topic