What is the value of `s` after: `s = 0` / `for i in range(2, 10, 4): s += i`?
Answer and explanation
Correct answer: A. 8
- Step 1: The loop uses i = 2, 6.
- Step 2: Their sum is 8.
Answer
8.
Why not the others: 18, 44 and 12 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.
More Python programming and algorithms questions
- What is the output of `print([x**2 for x in range(6) if x % 2 == 0])`?
- What is the output of `print([x**2 for x in range(4) if x % 2 == 0])`?
- What is the output of `print([x**2 for x in range(5) if x % 2 == 0])`?
- What is the output of `print([x**2 for x in range(4) if x % 3 == 0])`?
- What is the output of `print([x**2 for x in range(7) if x % 2 == 0])`?
- What does `'algorithm'[3:4]` return in Python?