Iterating over a list in a function


Oops, try again. total([0, 3, 6]) resulted in an error: list index out of range

n = [3, 5, 7]

def total(numbers):
    for i in numbers:
        print result
    return result


i contains the values from the list, not the indexes, so you can add i to result directly


Thank you very much !!


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