Modifying each element in a list in a function


#1

What's wrong with my code? I don't understand

n = [3, 5, 7]

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

print double_list(n)

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


#2

oh, i got it!

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)

#3

Don't feel bad... I did the exact same thing :relaxed:


#4

thanks,I had same problem