14/18 lists and functions something werid



<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
I passed this lesson but it didn’t follow the required task.

<What do you expect to happen instead?>
When I put range(3) in the empty my_function at line 6, the console returned [0, 2, 4].
However, if you check the lesson, the instructions say to return [0, 1, 2]; so what I’m confused about is whether this is a bug or some other reason that led me to pass this exercise not as intended.


Replace this line with your code.
For further reference, here is my code:
def my_function(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return x

print my_function(range(3)) # Add your range between the parentheses!

<do not remove the three backticks above>


Hi @bitrunner55888,

You did the exercise correctly, and the function, my_function, computed the expected result correctly as well.

The instructions state …

On line 6, replace the ____ with a range() that returns a list containing [0, 1, 2].

As intended, the range that you passed did return a list containing [0, 1, 2]. However my_function is designed to double each value in the list that is passed to it, and that is what it did. The result that got displayed reflects the combined work of the range and that of the my_function function.


Oh I assumed the code would return the exact list in the instructions but since you said it also doubles each value it all makes sense now.

Thanks for clearing that up as I continue to understand Python.