(Jan-15-2019, 07:41 AM)buran Wrote: In the first snippet you make res==0 before the loop and then only add i in every iteration of the loop. So at the end it's the sum of all values in range(x)
In the second example you make res==0 in every iteration. So at the end res value is equal to the last value of i.
You can use http://www.pythontutor.com/visualize.html#mode=edit to visualise the execution of the code step by step for better understanding
thank you it's much clear now