Modifying each element in a list in a function


#1

n = [3, 5, 7]
def double_list(x):
for i in range(0, len(n)):
x[i] = x[i] * 2
return x

print double_list(n)

thanks that worked but now whats wrong?


Printing out a list item by item in a function
#2

Hi @captainmowdy,

Here, you are accessing the global variable, n, when you should be accessing the function parameter, x ...

    for i in range(0, len(n)):

#3

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