Modifying each element in a list in a function


Oops, try again. double_list([0, 1]) resulted in an error: list index out of range

Replace this line with your code. 

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)


Hello luke.

This function actually deals with any general list that you named x

But here..

range(0, len(n))

in this line of code you're passing global list variable n.


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