๐ Explanation
-
Initialize s = 0
This variable will store the running sum. -
for i in range(1, 5):
range(1, 5) generates numbers 1, 2, 3, 4 (remember: 5 is excluded).
-
So the loop runs 4 times with values: i = 1, 2, 3, 4.
-
Loop execution (s += i)
-
Iteration 1: s = 0 + 1 = 1
-
Iteration 2: s = 1 + 2 = 3
-
Iteration 3: s = 3 + 3 = 6
-
Iteration 4: s = 6 + 4 = 10
-
-
Final Output
10
✅ Correct Answer: 10


0 Comments:
Post a Comment