Modifying each element in a list in a function


#1



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


Whats wrong with my code?


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
        return x
# Don't forget to return your new list!

print double_list(n)


#2

Is your function done by the time it reaches its return statement?


#4

meybe it should be::

def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
    return x

return x move out of the for loops .


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.