13. Modifying each element in a list in a function

#1

Oops, try again. double_list([0, 1]) returned None. Did you remember to return the result?

Return result *2 (i.e. 6, 10, 14)

``````n = [3, 5, 7]

for i in range(0, len(n)):
n[i] = n[i] * 2
# Don't forget to return your new list!
print double_list(n)

def list_function(x):
x[1] = x[1] + 3
return x

n = [3, 5, 7]
print list_function(n.``````

#2

from the instructions:

Use the existing code as a scaffold.

this is the code provided by the exercise:

``````n = [3, 5, 7]

for i in range(0, len(n)):
n[i] = n[i] * 2
# Don't forget to return your new list!
print double_list(n)``````

this means the for loop which is already present can be used for the function you have to build, make sure to name the function double_list

#3

Thanks for the response. I've played around a bit more and I'm not getting the error message below.

Oops, try again. double_list([0, 1, 2]) returned [0, 2, 2] instead of [0, 2, 4]

See updated code below:
n = [3, 5, 7]

for i in range(0, len(n)):
n[i] = n[i] * 2

Don't forget to return your new list!

def double_list(x):
x[1] = x[1] * 2
return x

print double_list(n)

#4

you decide not to use the code provided by the exercise?

currently, your function only multiplies the item at index 1 by 2, not all items, take a loop at the for loop provided to see how to achieve this

#5

I restarted from scratch and got where I went wrong. Thank you for the help!

#6