List Element Modification


#1

Hi

what is the error?

n = [1, 3, 5]

Do your multiplication here

n[1] = n[1] * 5
print n[1]

Error message: did u accidentally remove print statement that was on line 4.


#2

Try to print the whole list, instead of the 2nd element only


#3

But the instructions are:

On line 3, multiply the second element of the n list by 5


#4

1.On line 3, multiply the second element of the n list by 5

2.Overwrite the second element with that result.

3.Make sure to print the list when you are done!


#5

n = [1, 3, 5]

Do your multiplication here

n[1] = n[1] * 5
print n

this is the answer!!


#7

I liked your answer for this. I got the right answer too. I just don't understand why. In my mind I was thinking n[1] * 5

print n

It has been a while since I've started back studying Python on codecademy. Can you explain what is happening here with the n[1]=n[1]*5?

Thanks!!


#8

If you do n[1] * 5 you multiply 3 with 5 nothing more nothing less.
But if you do n[1]=n[1]*5? you multiply 3 with 5 and overwrite the current number of n[1].
-> n[1] equals n[1]*5


#9

Here is the code:-

n = [1, 3, 5]
n[1]=n[1]*5
print n


#10

this one is better:-
n = [1, 3, 5]
"""here we multiply the 2nd (index no. 1) element by 5 and overwriting it to the original list"""
n[1]=n[1]*5
print n