Question discussion

What is the output of the following Python code?print(7 // -2, 7 % -2, 2 ** 3 ** 2)

929Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

print(7 // -2, 7 % -2, 2 ** 3 ** 2)
  • A-3 1 64
  • B-4 -1 512
  • C-4 1 512
  • D-3 -1 64
Correct answer: B

Explanation

Floor division gives −4, the remainder takes the sign of the divisor (−1), and ** is right-associative so 2 ** 9 = 512.

Discussion 0

Nobody has replied yet. Start the discussion!