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?

<What do you expect to happen instead?
i dont understand whats wrong


Replace this line with your code. 
n = [3, 5, 7]
def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
# Don't forget to return your new list!
        
print double_list(n)


#2

if you need to return something use the return keyword

return the list (x) after multiplying every element inside the list


#3

yes so if i return it after x[i] = x[i] * 2, it gives an output as 3 which i understand that it ends the loop there itself.
when i print x[i] after that line, it prints the right values but throws and error saying - Oops, try again. double_list([0, 1]) returned None. Did you remember to return the result?


#4

a function ends the moment a return keyword is reached.

So you should place return outside the for loop so the whole loop can run


#5

i get it.. thanks for the help


#6