15/18

#1

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)

#2

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

#3

Hi,

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.

Pierre

#4

The return line should not be inside the loop.

#5

Thanks a lot.

It is always obvious when we get the anwser

#6

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

#7

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

#8

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

#9