0
why is this code's output is 6
def func(x): res = 0 for i in range(x): res += i return res print(func(4))
4 ответов
+ 2
So res = 0
x = 4
range(x) = range(4) which is 0, 1, 2, 3
0+0=0, 0+1=1, 1+2=3, 3+3=6
I hope you understand now
+ 2
The function sums all the numbers between 0 and x-1.
0
If you dont understand functions:
func(4) calls func(x) and sets x to 4.