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

20th Jan 2018, 8:34 PM
Aarnav
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
20th Jan 2018, 8:39 PM
᠌᠌Code X
᠌᠌Code X - avatar