12-13 Modifying each element in a list in a function


#1

I don't know why it can't work.

my code is below.

please help.

n = [3, 5, 7]

def double_list(x):
for i in range(0, len(x)):
x(i) = x(i) * 2
return x

double_list(n)


#2

Hello.
For list indexing remember to use brackets [] instead of normal ()


#3

thanks but it doesn't work.


#4

n = [3, 5, 7]
def print_list(x):
for i in range(0, len(x)):
print x[i]

print_list(n)

This is how you do it, with appropriate indents.


#5

thank you very much, this one helped me a lot!


#6

I think some of that code was removed, mainly multiplying everything by 2.

Try this, it includes all the parts of the code.

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)

/cheers