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))

11th May 2019, 5:28 PM
aziz
4 Antworten
+ 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
11th May 2019, 5:48 PM
marostar123
marostar123 - avatar
+ 2
The function sums all the numbers between 0 and x-1.
11th May 2019, 5:56 PM
Seb TheS
Seb TheS - avatar
0
If you dont understand functions: func(4) calls func(x) and sets x to 4.
11th May 2019, 5:49 PM
marostar123
marostar123 - avatar