+ 2
How the answer is 6 ?
def func(x): res = 0 for i in range(x): res += i return res print(func(4))
2 Answers
+ 14
for i in range(4)
//this loop will run for i=0,1,2,3
res +=i
//res +=(0+1+2+3) = 6
//try this code
def func(x):
res = 0
for i in range(x):
res+=i
print (res)
return res
print(func(4))
+ 2
Your not adding 1 each time. you are adding the iteration.
0+1+2+3=6