mushroom
mushroom

Reputation: 11

codeacademy python some questions about "range"

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

the code is :

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!

My code is:range(0,2,0.5),but it says it's wrong...

Upvotes: 1

Views: 513

Answers (3)

drewteriyaki
drewteriyaki

Reputation: 320

Putting something inside of my_range() just replaces the"x" in def my_fuction(x). When you out something inside the parenthesis, all it does is replace your arguments. If you print the calling, it won't let you call it again because you already assigned those variables.

Upvotes: 0

rnevius
rnevius

Reputation: 27092

A range() that returns a list containing [0, 1, 2]...That would be: range(3).

They're asking you to output [0,1,2] where the underscore is (line 6), not for [0,1,2] to be output by the function. It's a poorly-worded question.

So, simply, the answer is to put range(3) on line 6. This will cause the function to return [0, 2, 4].

Upvotes: 1

Diego Basch
Diego Basch

Reputation: 13059

That exercise is poorly written. It would be impossible for the output of my_function to be [0, 1, 2] because you'd need a 0.5 in the input range. Still, it's unclear if that's what the problem is asking you to do. See the discussion here.

Upvotes: 0

Related Questions