Modifying each element in a list in a function


@stetim94 You've got to help me out. This lines of codes are not working ! I'm dead stuck
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)

This is the error message I get:
Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2]

This is the output i get:
[6, 5, 7]

why is this ?


Check the indentation on that line. It should not be inside the loop.


Thanks @mtf I figured it out. Grateful


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