15/18 Iterating over a list in a function Method 1
Since we aren’t modifying the list, feel free to use either one on this lesson! Create a function that returns the sum of a list of numbers. Create a function called total that adds up all the elements of an arbitrary list and returns that count, using the existing code as a hint. Use a for loop so it can be used for any size list.
My code is:
n = [3, 5, 7] def total(numbers): result = 0 for i in numbers: result += numbers[i] return result print total(n)
Why it dosn’t work? err msg: Traceback (most recent call last): File “python”, line 8, in
I got no problem with Method 2