Modifying an element in a list of a function


#1

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

plz i dont know what to do plz explain and tell me what the instructions need me to do exactly
error:

Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2]
exercise link:
https://www.codecademy.com/courses/python-beginner-nzzVa/3/2?curriculum_id=4f89dab3d788890003000096#


#2

Remove that line. We don't want to multiply the list by 2, but the values in the list, as the next line is doing.


#3

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

return x

print double_list(n)

As you can see, our code is very similar. There are a few differences though.
1. I don't have x * 2 because this further multiplies it which we don't need
2. When setting your range, ensure you are using the input argument (x) as your condition for len() not the list name (n).


#4

I'm having an issue where it is only multiplying the first item.
Here is my code:

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

print double_list(n)

On the console I get:
[6, 5, 7]
None

And the error message I get is:
Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2]


#5

Try returning the value outside of the for loop.


#6

guys thx i solved from so long but i forgot to tell you sorry


#7