Modifying each element in a list in a function


#1

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

why is this ?


#2

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


#3

Thanks @mtf I figured it out. Grateful


#4

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