Stuck


#1



n = [3, 5, 7]

def total(numbers):
    result=0
    for item in numbers:
        result+=item
        return result 

Create a function that returns the sum of a list of numbers.

On line 3, define a function called total that accepts one argument called numbers. It will be a list.
Inside the function, create a variable called result and set it to zero.
Using one of the two methods above, iterate through the numbers list.
For each number, add it to result.
Finally, return result.


#2

Be sure your return statement is not inside the loop.


#3

n= [3, 5, 7]

def total(numbers):
result=0
for item in numbers:
result+=item
return result
I GET THIS ->File "python", line 7
return result
^
IndentationError: unindent does not match any outer indentation level


#4
def ___():
    for ____:
        # loop code
    return ____

#5

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