15/18 Explanation of Code?


#1

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?


#2

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


#3

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