Modifying each element in a list in a function


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)

Here what I did wrong ?


a function ends the moment a return keyword is reached, if a return keyword is reached in a loop, the loop breaks


Thanks it worked........:slight_smile: