Modifying each element in a list in a function


#1


https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/2?curriculum_id=4f89dab3d788890003000096#

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)


#2

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


#3

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