Let’s break this code step by step so it’s crystal clear.
๐น Code:
๐ Explanation:
-
Initialize:
s = 10 -
Loop:
The for loop runs with i taking values from 1, 2, 3 (because range(1, 4) stops before 4).-
Iteration 1 (i = 1):
s -= i * 2 → s = s - (1 * 2) → s = 10 - 2 = 8 -
Iteration 2 (i = 2):
s = 8 - (2 * 2) → s = 8 - 4 = 4 -
Iteration 3 (i = 3):
s = 4 - (3 * 2) → s = 4 - 6 = -2
-
-
After Loop Ends:
s = -2 -
Print:
Output → -2
✅ Final Output:
-2


0 Comments:
Post a Comment