🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Matrix Traversal: all 13 questions

Quiz: Matrix Traversal · Question 11 of 13

What does this print? (code)

What does this print?

m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
n = len(m)
print(sum(m[i][i] for i in range(n)) + sum(m[i][n - 1 - i] for i in range(n)) - m[1][1])
  1. A.30
  2. B.15
  3. C.25
  4. D.20
Answer & explanation

Correct answer: 25

Both diagonals sum to 15, but the centre 5 belongs to both, so it is subtracted once: 15 + 15 − 5 = 25.

Can you get the rest right without peeking?

Take the timed Quiz: Matrix Traversal quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →