13/18 - I'm clueless about this one


#1
n = [3, 5, 7]

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

print double_list(n)

Console output:
[6, 5, 7]
None

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

I just don't know what I'm doing wrong.


#2

Well you start the function with double_list(n). There you enter the for loop and change the first value. So far so good. And then you return and that is the problem as you're still in the first loop. So just move that return 4 spaces back so that it is executed after the for loop is done and you should be fine.


#3

Thank you so much. Everything is fine now.

n = [3, 5, 7]

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

print double_list(n)