Modifying an element of a list in a function: wrong output


#1

Hi,

I am using following code, but my output is different than what I am expecting (it is adding 6 at the place of 3 in 2nd element of the list). But I am not getting any error and passing the exercise.
Can you suggest if my code is correct or not and what should be my output.

def list_function(x):
    x[1]=x[1]+3
    return x

n = [3, 5, 7]

list_function(n)

print list_function(n)

output

[3, 11, 7]
None


#2

Hi @er.madhukar,

I suspect the main problem is when you did this:

Which resulted in you calling the function twice successively, giving you 5 + 3 + 3 :stuck_out_tongue:


#3

Thanks!
Yes it worked.


#4

You're welcome :slight_smile:


#5

but still not sure, why it didn,t throw any error and let me pass this test :wink:


#6

Probably because this exercise is mainly testing for the function itself, which you did get right :stuck_out_tongue: