Python: Lists & Functions, Lesson 14 Passing a Range to a Function is not written in proper English and has bugs


#1

https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/3

Python: Lists & Functions, Lesson 14 Passing a Range to a Function is not written in proper English and has bugs:

This topic was archived by the moderator w/o a resolution. (By a moderator who claims not to like Codecademy; so why is he a moderator at all? Seems inappropriate to allow.)

Per the moderator, factoradic, the correct answer to Python: Lists & Functions, Lesson 14 Passing a Range to a Function is to pass in range(3), which does allow one to 'pass' the lesson. However, passing in range(3) does not adhere to the directions in the question.

The directions in the question read to "replace the ____ with a range() that returns a list containing [0, 1, 2]." With the way the body of the function is written, there is no int range one can pass to obtain a return comprising list[0,1.2].

Passing in range(3), as the program accepts and the former moderator states is the correct answer returns list[0,2,4].

List[0,2,4] != list[0,1,2]

Regardless of the former moderator's refusal to see this fact, this question is not written correctly. It's neither correct in it's English content, nor mathematically. There is no range one can pass into this function...

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

...That will return x = [0,1,2] as the question's directions state the student is to return. Not only does the 'correct' answer per the moderator not adhere to the directions in English, but the only way to make them do so would be to change the body of the function and overload the method range() to accept floats as arguments. Therefore, not only is the English written poorly, the answer not mathematically correct, but the function as it's written is incorrect in its algorithm -- it has a logic error.

There's no way logically to get an output return of x=[0,1,2] as this question is written. Either the question is wrong or the 'answer' is wrong, and one or the other should be edited. There's no way you can make
List[0,2,4] = list[0,1,2,]. One of them has to be wrong.

Since in coding you're getting the wrong output or return than what is asked and expected, this code by definition has a bug in the form of a logic error. The topic should not have been archived. The bug needs to be fixed. The former moderator should not be refusing to see the bug. It's plainly there. If you can't get the output you're supposed to, that's a bug!


#2

Hm.... looking at the exercise, i would get confused what to do. I will see if this already a reported problem, and if it can be fixed :slight_smile: Thank you for letting us know :slight_smile:


#3

Hi Heather,

This exercise is asking you to pass in:

a range() that returns a list containing [0, 1, 2]

It is not asking you to make my_function() return [0, 1, 2], it only cares that range() returns [0, 1, 2].


#4

There is no range you can pass in to:

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

To get a return of list [0,1,2].

(At least, not without rewriting the function range() and overloading it.)

update 4/17/16: albionsrefuge, range() is what you're using as an argument and a parameter. It doesn't give you a return. The method...

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

...Is what gives the return. And, there is no range you can pass into this method to get a return of [0,1,2].

The directions in the question very clearly state you're to get a return [from the function as that what's gives a return, not range] by " "replac[ing] the ____ with a range() that returns a list containing [0, 1, 2]." The blank ___ is the argument and parameter for the above function.

There is no range you can pass as argument into the above function and have it return [0,1,2]. (At least, not without overloading range(). )

If there is, please tell me what that range is?

The question currently takes range(3) as the correct answer, which returns [0,2,4], not [0,1,2]. And, that's not because you're only to pass in any range or get a return from range. The directions read to pass in a range [to the function] "that returns a list containing [0,1,2]." Functions give returns; arguments are passed into functions; and parameters are taken in by functions. Arguments and parameters don't give a return.

The argument range() doesn't give a return. (Even inside the library method range() -- if you want to argue you're passing a method, so it gives a return -- is just a For Each loop. Loops don't give returns. You can print, or save to memory in a variable the results of a loop, but loops don't give returns without that. Otherwise it begs the question, range of what? Range start at 0, go to 2, stop before 3, and step by 1 of what? Loop through what? Asking for a return just from range(), without telling the compiler what to loop through, would be a logic error.)

Lastly, why can I no longer post replies here? This topic should still be open.


#5

Thank you!

Has anyone fixed this yet?

I keep getting emails from the forum of people not reading the question correctly... :disappointed:

update 4/27/16: Ok, no worries. Thanks for looking into the fix.


#6

fixes take a while, plus you just need to pass a range into the function call. You where to focused on what the function should return


#8

Yes, that's right!

You shouldn't be caring about what my_function returns.

You only need to care about what range() returns.