+ 3

Please explain

Can you explain why the answer is: 6 def func(x): res = 0 for i in range(x): res += i return res print(func(4))

5th Mar 2020, 7:40 PM
chris mueller
chris mueller - avatar
1 Answer
+ 4
This( for loop) start from value i=0 to i=3 for x=4 so res = 0+1+2+3 =6
5th Mar 2020, 7:45 PM
Mehrdad Sh
Mehrdad Sh - avatar