ProgrammingHardGATE CS · Product-company placement

What is printed on the first line?

What is printed on the first line?
n = -17
print(n >> 2, n // 4, n & 3, n % 4)
print(n << 1, (n << 1) >> 1 == n, ~n)
  1. A. -5 -5 3 3
  2. B. -5 -4 3 3
  3. C. -4 -5 3 3
  4. D. -5 -5 3 -1

Correct answer: A. -5 -5 3 3

Right shift on a negative int floors, matching // 4. The low two bits of -17 are 11, so n & 3 and n % 4 both give 3.

More Python Programming questions

Exams that ask this topic