What is the value of `s` after: `s = 0` / `for i in range(2, 12, 2): s += i`?

Answer and explanation

Correct answer: B. 30

  1. Step 1: The loop uses i = 2, 4, 6, 8, 10.
  2. Step 2: Their sum is 30.
Answer
30.
Why not the others: 42, 65 and 32 do not fit.

Practise more Python programming and algorithms.

Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.