Could someone please explain what this one is asking me to do?
here are the instructions:
On line 6, replace the ____ with a range() that returns a list containing [0, 1, 2].
after defining n as [0,1,2]
Nothing should happen in this code as I read it. there's no referenced data to manipulate within the function if you pass it a range.
all I see is, for each item in x multiply it and store it back into x.
passing a list, instead of a range, with 'n' being = to [0,1,2] returns a result of [0,2,4] which is accepted as a good answer, even though it's not what was asked for.
def my_function(x): for i in range(0, len(x)): x[i] = x[i] * 2 return x print my_function(____) # Add your range between the parentheses!
This code gives the proper response, but is not accepted because I did not pass it a list containing [0,1,2]( note that I had to add the int() function because .5 * 2 equals 1.0 which is not a good answer either.
def my_function(x): for i in range(0, len(x)): x[i] = int(x[i] * 2) return x n = [0,.5,1] print my_function(n) # Add your range between the parentheses!
So, am I out of my gourd or is the question just wrong?
As I see it you cannot pass the [0,1,2] list it requires you to pass,
nor can you pass a range to the function as it says to, you have to pass a populated list for it to function,
and if you give it the data it says to, you get an incorrect returned value unless you change the code of the function.