1

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...

4
  • 1
    The function takes a single parameter, you know? Commented Sep 27, 2014 at 6:22
  • 1
    You need to pass a list to that function.? Commented Sep 27, 2014 at 6:32
  • 1
    You have misread the question; it's the call to range that should return [0, 1, 2], then the call to my_function should return [0, 2, 4]. Commented Sep 27, 2014 at 7:07
  • Was your question answered? Or do you require further clarification? Commented Sep 27, 2014 at 15:14

3 Answers 3

1

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].

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.