Understanding the Code
s = 1: Initial value of s.
range(1, 4) → iterates over i = 1, 2, 3.
The update in the loop is:
Which is the same as:
๐ Step-by-step Execution
๐งฎ Iteration 1 (i = 1)
๐งฎ Iteration 2 (i = 2)
๐งฎ Iteration 3 (i = 3)
✅ Final Output
๐ง Shortcut Insight:
You’re actually computing:
That’s 1 × 2 × 3 × 4 = 24, so it's calculating 4! (factorial of 4).


0 Comments:
Post a Comment