Modifying each element in a list in a function


don't know what's wrong error message reads:
Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2]

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

print double_list(n)


The function ends on return. Therefore, your function ends on the first loop.


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