Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2] getting this error


#1

n = [3, 5, 7]
def double_list(x):
for i in range(0, len(n)):
x[i] = x[i] * 2
return x

Don't forget to return your new list!

print double_list(n)

Replace this line with your code.


#2

your for loop:

for i in range(0, len(n)):

because you use n, your function will only work for one fixed list, not any list supplied as argument on function call.


#3

Oops, try again. double_list([0, 1]) returned [0, 1] instead of [0, 2]

gettin this error

below is the code

n = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return x

Don't forget to return your new list!

print double_list(n)


#4

A function ends the moment a return keyword is reached, if the return keyword is reached in a loop, the loop simply breaks.

Use markup next time when posting your code:

This makes spotting indention problems a lot easier


#5

can u tel me whats exactly wrong in this code
???


#6

In your case, the return keyword is reached in the first iteration of the loop, causing the loop to break at the end of the first iteration.


#7

where am i supposed to place the return then ??


#8

outside/after the for loop, this way, the whole loop can run


#9

done got it right... thanks


#10