total holds the sum of all squared values, so the first time i = 3 so i**2 = 9, and total += i**2 means total = total + 9. The value for total here is 0 so total = 0 + 9 and now total is 9.
The second time i**2 = 16 so total = total + i**2 is 9 + 16 and therefore total = 25 now.
And the third time i**2 = 25 so total = 25 + 25 and total = 50
All we need to do now is to return it
and that's it.
Hope this helps :)
If not I'll try to explain it better :)
yup thts exactly wht i meant... and + would mean it squares every number and add it to the total and moves on the next without leaving any out.. yup tx for the help... appreciate it... nw i get it..
but one last question, why is the total=0? is tht like a rule that it has to equal 0?
well when you want to count stuff or find a sum of numbers you need the count, or whatever variable name you use, to be initially 0 because if it's 1 or more or 0 and less you will get incorrect results. Basically this is what I mean:
>>>total = 1
>>>total = total + 5**2
26 # but 5**2 is 25 so total has to be 0
the statement total = total + 5**2 means compute the sum of the current value of total and the square of 5 and replace the current value of total with the result of the computation :)