Hey everyone, I’m pretty stumped on this. Could anyone guide me towards the correct answer. Here’s my code

n = [3, 5, 7]

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


We need to assign that expression back on to the variable.

result = expression

or using the compound assignment operator,

result += value

There is a bigger problem though, and that is the iterator variable. It should have a different name than the running count.

total = 0
for number in numbers:
    total += number
return total



Thanks mtf for your help.

I don’t get it neither. If I understand well, the exercice want us to return the last logical number of the list : 9.
For me return = 0 instead of 9 with the following code :

n = [3, 5, 7]

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

But I’m not sure where I missed something.

Thanks for your help,



The return line should not be inside the loop.


Thanks a lot.

It is always obvious when we get the anwser :sweat_smile:


Isn’t it though. Still should not dissuade one from asking. We all have mental blocks and need a spur, time to time.


Yes thanks again,

So the return line is inside our outside the loop depending of the indentation only ?
(I see it blue or white depending on that)

Sorry to relaunch you on this but I’m not sure I fully understood


Exactly. Indentation is how Python discovers block structures, which is how it defines function scope and block scope in general.


Thanks again for your time and answer


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