15/18 Explanation of Code?


n = [3, 5, 7]

def total(numbers):
result = 0
for i in range(,len(numbers)):
result += numbers[i]
return result

I’m confused about the i in numbers[i] to be honest and to way result+= numbers[i] works but result = result + numbers[i] doesn’t?


That won’t run at all.

If you say X works but Y doesn’t, then I’d really want two full pieces of code to compare containing X and Y respectively. My initial reaction without thinking too hard about it is that your observation is probably wrong in some way. But I’m unable to see the same thing without the aforementioned full examples.

And if you’d have me fix these things “myself” then 1) you can make it that much easier to answer 2) my effort is spent on the wrong thing, reducing effort spent on what matters 3) I’d be unlikely to end up with the same thing since I’d probably have to introduce the same mistakes


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.