Explanation:
Line 1: range(5)
range(5)
range(5) generates numbers starting from 0 up to 4.
It does not include 5.
Generated values:
0, 1, 2, 3, 4
Line 2: sum(range(5))
sum(range(5))
sum() adds all numbers produced by range(5).
Calculation:
0 + 1 + 2 + 3 + 4
= 10
So:
sum(range(5))
returns:
10
Line 3: print(...)
print(10)
print() displays the result on the screen.
Output:
10
Complete Execution Flow
Step Expression Result
1 range(5) 0, 1, 2, 3, 4
2 sum(range(5)) 10
3 print(10) Displays 10
Final Output
10

0 Comments:
Post a Comment