List element modification


#1

n = [1, 3, 5]

Do your multiplication here

for x in n:
x= n[2]*5
n[2]=x
print n

Oops, try again. Did you remember to multiply the second element in the list by 5?
Somehow, I'm lost on basic on lists, though not sure where

Instructions
On line 3, multiply the second element of the n list by 5
Overwrite the second element with that result.
Make sure to print the list when you are done!


#2

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

Your code is using the third element (index) "[2]", not the second, "[1]".

There might be more to it but that's what I noticed off the bat, see if that helps.


#3

That's what I'm not getting here... what is the code to multiply the element from the list without using for


#4

Yeah i got stuck on this as well.
here's what i did that wasn't working: n = [1, 3, 5]
n[1]= n[1]*5
n.append(n[1])

                                                 print n

It was working but instead of overwriting the number 3 or [2] with 15, it would just add 15 to the list in index [2] and push the number 3 to index[3] and so on.
so i just deleted the append line and it worked: n = [1, 3, 5]
n[1]= n[1]*5

                                                               print n

def over thought that one. hope that helps!


#5

sorry, that didn't copy and paste right.


#6

Thanks mate....That helped


#7

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