Modifying each element in a list in a function


stuck. pls anyone?

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

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


a function ends the moment a return keyword is reached, which in your case happens in the first run of the loop, you might want to re-indent the return so your whole for loop can run

This solves your current problem, first please try to solve the other problem. Of course, if you need more help with this exercise you can reply in this topic


yes i found where is my problem