+ 1

I don't understand this, what does this do?

def func(x): res = 0 for i in range(x): res += i return res print(func(4))

3rd Oct 2020, 5:09 PM
Kyber Chaos
Kyber Chaos - avatar
3 Answers
+ 4
Maybe python would be a good tag for the question.
4th Oct 2020, 12:46 AM
Sonic
Sonic - avatar
+ 4
func(x) gives the sum of numbers from 0 to x-1.
4th Oct 2020, 12:47 AM
Sonic
Sonic - avatar
+ 1
For future reference, please tag a relevant language to improve context clarity ... ☝
3rd Oct 2020, 5:56 PM
Ipang