0
¿por qué este codigo devuelve el valor 6?
What is the output of this code? def func(x): res = 0 for i in range(x): res += i return res print(func(4))
1 Respuesta
0
Because it is a sum of 1 +2 + 3 + 4 + ... + n, then this sum is equal to:
n(n-1)/2
Replace n = 4 and the result is 6.
Cheers