+ 1

output of code (py)

def func(x): res = 0 for i in range(x): res += i return res print(func(4)) output of this code is 6 and please help me to understand why..

27th Jun 2019, 9:09 PM
Dato InLostPlace
Dato InLostPlace - avatar
3 Answers
+ 1
What result did you want to get?
28th Jun 2019, 5:01 AM
Š˜Š³Š¾Ń€ŃŒ Щенев
Š˜Š³Š¾Ń€ŃŒ Щенев - avatar
+ 1
You added all the integers in a range object to variable res. range(4) = 0, 1, 2, 3 res = 0+1+2+3=6 res was returned as 6, and 6 was printed.
28th Jun 2019, 8:06 AM
Seb TheS
Seb TheS - avatar