13. Modifying each element in a list function-Oops, try again. double_list([0, 1]) resulted in an error: list index out of range


#1



13 Modifying each element in list function


Expect it to work


 = [3, 5, 7]
def double_list(x):
    for i in range(0, len(n)):
        x[i] = x[i] * 2# Don't forget to return your new list!
    return x
print double_list(n)


#2

Your list has no variable name.


#3

It does, It just disappeared in copying

n = [3, 5, 7]
def double_list(x):
for i in range(0, len(n)):
x[i] = x[i] * 2# Don't forget to return your new list!
return x
print double_list(n)


#4

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


#5

Here, instead of len(n)) use x. so,

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


#6

Thanks! I knew it was something stupid I had just forgot


#7

you're welcome :grin:


#8

@bandit @rootjr def list_function(x):
return x[1]

n = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] + 3 OR * 2 <-------
return x
print double_list(n)
print list_function(n)

Change list_function so that:

Add 3 to the item at index one of the list.
Store the result back into index one.
Return the list. what am i doing wrong, did they change this lesson because everyones cose multiplies by two instead of adding 3 im confused


#9

What are you trying to do with this line?