12/15 Iterating over a list in a function helpe


#1

this is my code
n = [3, 5, 7]

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

error massage (Oops, try again.
total([0, 3, 6]) returned 3 instead of 9)


#2

The for loop you created will just be numbers at each iteration. The intent here is that each number is a valid index in the given list. hence you must modify this line

result= i +result

to be

result= numbers[i] +result

#3
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
    results=[]
    for numbers in lists:
        for x in numbers:
            results.append(x)
    return results


print flatten(n)