13. Modifying each element in a list in a function


#1



13. Modifying each element in a list in a function


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

The function returns [6, 5, 7]


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

Fix the indentation!


#3

n = [3, 5, 7]

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

This had me stumped for a while but yeah, all you need to do is indent. The struggle is real.


#4

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