Can't multiply any list by 2


#1



Hello evryone :slight_smile:

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

My code is behaving incorrectly as it does not return any list multiplied by two but instead returns n. anyone know why ?

I happen to return all the items of any inputed list by 2

my code: 

n = [0, 2, 3]
def double_list(x):
    for item in range(0, 1):
        item = item * 2
        return n
print double_list(n)


Thanks in advance,


#3

Your double_list(x) should iterate through a list passed as argument to this function.
Change your for to iterate over all list, not only over first and second element.

def double_list(x):
    for index in range(len(x)): # len(x) returns length of list
        x[index] *= 2 # x[index] *= 2 is same as x[index] = x[index] * 2
    return x # return should be after loop, not inside

#4

Thank you for your answer. I really apologise for not checking code academy sooner.