Step 1:
count = 0
We start with a variable count and set it to 0.
Step 2:
for i in range(1, 5):range(1,5) means numbers from 1 to 4
(remember, Python stops 1 number before 5)
So the loop runs with:
Step 3:
count += i means:
count = count + iSo step-by-step:
| i | count (before) | count = count + i | count (after) |
|---|---|---|---|
| 1 | 0 | 0 + 1 | 1 |
| 2 | 1 | 1 + 2 | 3 |
| 3 | 3 | 3 + 3 | 6 |
| 4 | 6 | 6 + 4 | 10 |
Step 4:
print(count) prints 10
✅ Final Output:


0 Comments:
Post a Comment