0
Python question
Why is the output of this code 6? def func(x): res = 0 for i in range(x): res += i return res print(func(4)) 6
1 Answer
+ 5
for i in range(4) and items in range 4 are:
0,1,2,3
so res+=1+2+3
therefore res=6
Why is the output of this code 6? def func(x): res = 0 for i in range(x): res += i return res print(func(4)) 6