There is something wrong with the instructions here


#1

There is something wrong with the instructions here, I compiled this:

x = [0, 1, 2]
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!

Result is this:
[0, 2, 4]
None

which is wrong. The expectation was to return a list containing [0, 1, 2].


14. Passing a range into a function. Problem. error
#2

@13kiran
Use

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

and look at the output....


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.