0
I know the output, but I still do not understand why this is the output.
Could anybody please explain this? def func(x): res = 0 for i in range(x): res += i return res print(func(4))
4 Respuestas
+ 5
range (4) expands to the list 0, 1, 2, 3
i = 0
res = 0 + 0 = 0
i = 1
res = 0 + 1 = 1
i = 2
res = 1 + 2 = 3
i = 3
res = 3 + 3 = 6
Does that help?
+ 4
Actually with the in range syntax you create an array. So your statement could have been as follows:
var x[4]. instead
+ 1
Oh my god, I suddenly see it!
Thank you so much :-)
0
It says the answer is 6.
I do not see how to get to 6...