14/18 I dint learn anything in this lesson (ps there is no hint) [poorly written lesson


#1

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

print my_function(range(0,3,1)) # Add your range between the parentheses!
Yes this is the correct code, the awnser is [0, 2, 4].which is 2x of [0,1,2], but [0,1,2] are nowhere to be found in the code so how does it know to execute the numbers in that list!
Also there is no hint!


#2

I have added some print statements to the code you have there just to help you keep track of what is happening if you still have problems understanding

def my_function(x):
    
    print("This is the original list x --> %s\nNow we change it -->\n"%(x))
    for i in range(0, len(x)):
        print("at position %s --> %s change to %s"%(i, x[i], x[i] * 2))
        x[i] = x[i] * 2
        print("The list x is now %s\n"%(x))

        
    return x
# you can provide just one argument to range and itis = range(0,3,1)
print my_function(range(3))

The original list does not exist anymore because you are directly changing the elements inside it. To avoid this you can create a new list and add the changes to it.

it is a good idea to add print statements to block of code(as a debugging method) to help you keep track of what is going on and whats not going right