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

27th Apr 2020, 10:38 PM
Francisco Crescencio Farina Remonda
Francisco Crescencio Farina Remonda - avatar
1 Answer
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
3rd May 2020, 6:45 AM
Kevin Hernandez
Kevin Hernandez - avatar