Step 1: Initial value
s = 10Step 2: Loop range
range(1, 4) → values are 1, 2, 3
Step 3: Iterations
-
When i = 1 → s = 10 - (1*2) = 8
-
When i = 2 → s = 8 - (2*2) = 4
-
When i = 3 → s = 4 - (3*2) = -2
Step 4: Final result
After the loop ends, s = -2
So the program prints:
Output → -2
✅ Explanation:
Each iteration subtracts i*2 from s. Starting from 10, after subtracting 2, then 4, then 6, the result becomes -2.


0 Comments:
Post a Comment