Iterating over a list in a function


Guys, guys. So in this lesson, they ask you to complete it using 1 of 2 methods.

The 1st method uses: "for item in list:"

The 2nd method uses "for i in range(len(list)):"

I can figure out how to solve the lesson using method 1. But can't figure out how to solve it using method 2. halp plz

n = [3, 5, 7]
def total(numbers):
    result = 0
    for x in range(len(numbers)):
        result += x
    return result


range() will give you a list which matches the indexes of list numbers, so then you need to:



Awesome, thank you for your help!