Explanation:
1. Create the Range
x = range(10, 0, -3)
Here, range() takes three arguments:
range(start, stop, step)
So:
Start = 10
Stop = 0
Step = -3
2. Understand the Negative Step
Because the step is -3, Python moves backward by 3 each time.
Starting from 10:
10 → 7 → 4 → 1
Python stops before reaching 0.
So x effectively contains:
10, 7, 4, 1
3. sum(x)
sum(x)
The sum() function adds all values in the range:
10 + 7 + 4 + 1
Calculate:
10 + 7 = 17
17 + 4 = 21
21 + 1 = 22
Therefore:
sum(x) = 22
4. print() Displays the Result
print(sum(x))
Python prints:
✅ Final Output
22

0 Comments:
Post a Comment