result = result += numbers[i] ^ SyntaxError: invalid syntax
I don't know why formatting is not working for me in this post.
I've puzzled over this for about 20 minutes now and after searching I'm no nearer a solution. I've tried altering my code to match what I've seen others use or just bits suggested in their posts and still I'm confused.
If I take out "result =" and leave it at £result += numbers[i]" I get "Oops, try again. total([0, 4, 1, 5]) returned 5 instead of 10" and that just confuses me even more.
Here is my understanding of the exercise broken down by line.
n is a list of 3 items and they are at index (0, 1, 2).
In my function "total" it stores "numbers" (is this telling Python that it will be actual numbers or is that for my reference?)
Then I set a variable of "result" to "0".
For every i (is that short for item?) in the range from 0 to the legnth of the range (3 in n)
Add the number from the list to the result variable.
Return the result (which is the total)
Hopefully someone can point out what I'm confusing or understanding incorrectly because I refuse to just look for someone else's answer until it works. I won't learn anything that way.
n = [3, 5, 7] def total(numbers): result = 0 for i in range(0, len(n)): result = result += numbers[i] return result