Codecademy Forums

How can we select the last few elements of a list?

Are you referring to my post of Aug. 12?
Have you thus far studied while or for loops?

yes man actually i did start this course recently now am reaching that topic yeh for loop a little bit

I think that once you’ve studies loops a bit, the answer will become obvious. If not, come on back here.

ok thank you very much . but in this question loop is not using am talking about the problem add last tow digit of lst and append them

The input list must be at least two elements in length so that we can use negative indices.

 lst[-2]

and

lst[-1]

That will give us the last two elements in the list.

Now we just add the two and append the sum to the list.

lst.append(lst[-2] + lst[-1])