+ 2

Can someome please explain why the result here is 6 ?

def func(x): res = 0 for i in range(x): res += i return res print(func(4)) and why if I change the number 4 with 5 I will get 10. thank you

30th Jan 2020, 11:09 PM
Sergiu Simion Faragau
Sergiu Simion Faragau - avatar
2 Réponses
+ 2
Because i is being incremented each loop so. 1 + 2 + 3 + 4 + 5 ...
30th Jan 2020, 11:12 PM
Gevork Bagratyan
+ 2
thank you very much, now I understand
30th Jan 2020, 11:13 PM
Sergiu Simion Faragau
Sergiu Simion Faragau - avatar