0

Hello, can some one tell me how to out put the last item on a list

I'm trying to do a test task and it tells me that I need to out put the last item on a list, but I'm having problem, and that is that I have to out put the last item on a list that has to be created by an input. Because the information that came from an input is a random information a don't know how to out put the last item. Other problem that I have, is that from the input thy want to put information like this: 4 66 7 894 And with an input it just take one like just the first number not the others. I don't know if I explain my self in a right way or not, but if someone can help me it would be so helpful. By the way this is the test task: Write a program that takes a list as input and takes the last item out of that list. The list of entries can be of any size, remember that you can use negative indexes to index the lists.

23rd Sep 2021, 7:43 PM
Alan Restrepo
Alan Restrepo - avatar
3 odpowiedzi
+ 2
To get the last item of a list li use li[-1]
23rd Sep 2021, 7:46 PM
Simon Sauter
Simon Sauter - avatar
+ 2
As to the input. I'm not sure if this is what you mean, but sololearn often gives you several numbers in one line separated by spaces as input. You can turn these into a list like this: li = input().split()
23rd Sep 2021, 7:49 PM
Simon Sauter
Simon Sauter - avatar
0
Simon Sauter thank you, I'm gonna try what you show me
23rd Sep 2021, 7:55 PM
Alan Restrepo
Alan Restrepo - avatar