14/18 it is not return [0 1 2] but I passed?


#1

it is not return [0 1 2] but I passed ?

it needs [0,1,2] in return ,but I didn t.

here is my code

def my_function(x):
for i in range(0, len(x)): #len[0,1,2]=3 so range(0,3) is [0,1,2]
x[i] = x[i] * 2
return x # and it becomes [0,2,4] in the end
print my_function(range(0,3,1)) # I think it is [0,1,2]

plz help thank u so much!! :joy:


#2

Yes, I thought the same thing, the wording is confusing, it is asking for the range function to return that list, but then my_function doubles the elements in the list before it's printed so that list is correct.


#3

it is so weird
and lots of people did this


#4

see below foe right ans. yo need to pass the range for [0,1,2,] that is range (0,3 )#not includes 3


#5

[0,3,1] not includes 3 too and you are [0,2,4] too


#6

check this part
def my_function(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return x
this part make the list you returned multiplied by two so your code
print my_function(range(0,3,1))
returned [0,1,2] but since it used 'my_function' it becomes [0,2,4]

Hope this helps :grin:


#7

Bear in mind that the default step is 1, making it redundant to add it; so putting either range(3) or range(0,3) yields the same result.


#8

Exactly! If the user reads the instructions carefully, it is only range() that is required to return [0,1,2]. So in rigidly logical terms, the instructions are clear.

But given that the overall output is ordinarily the primary concern, I think that it's natural for this confusion to arise. I'd recommend that they change the wording of the instructions to avoid this natural confusion occurring. What do you reckon?