Modifying each element in a list in a function - list index out of range error


#1



https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/2?curriculum_id=4f89dab3d788890003000096#


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


n = [3, 5, 7]

# Don't forget to return your new list!

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


#2

You are attempting to get the length of a list, n. However, inside the function, it does not know what n is.

The function will use the placeholder x until you call the function itself on n, at which time it will replace the x throughout the function with n.


#3

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