0

output

I don't understand, the output of def func(x): res = 0 for i in range(x): res += i return res print(func(4)) is 6, but shouldn't it be 10? because 1+2+3+4=10? I am confused

15th Apr 2020, 10:49 PM
gianni brambilla
gianni brambilla - avatar
1 ответ
+ 2
for i in range(x) -> excluding x i starts at 0 and ends at 3. You can see it when you add a print statement inside the loop.
15th Apr 2020, 11:11 PM
Denise Roßberg
Denise Roßberg - avatar