Modifying each element in a list in a function


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

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)):


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