Slice List - Pro Exercise | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Slice List - Pro Exercise

x = input() elements = x.split() #your code goes here list = x[::-1] print(list[0]) Hello Guys ! In this exercise about the slice list, my program work sucessfully with all the test, but only the second isn't working. This second is just the number 42. I understand that the code slice the 42 in 4 and 2. It give me the result 2 but I don't know how to fin that without impact all the result of other test. Can you give me advice about this exercise ? Thanks community !

31st Aug 2020, 1:53 PM
Greg GS
Greg GS - avatar
8 Respostas
+ 1
1.What is the task? 2. never ever ever never redefine predefined (built-in) function names!!!
31st Aug 2020, 2:01 PM
Shadoff
Shadoff - avatar
+ 1
try this, it has to work. x=input() print(x[len(x)-1])
31st Aug 2020, 2:30 PM
Shadoff
Shadoff - avatar
+ 1
Greg GS , can you just make it clear? You said last element of a list. Here you are. What 2, what 4???
31st Aug 2020, 2:48 PM
Shadoff
Shadoff - avatar
+ 1
Ok then. print(elements[-1:])
31st Aug 2020, 3:23 PM
Shadoff
Shadoff - avatar
+ 1
x=input() mylist = list(x.split(' ')) print(mylist[-1]) Hi Greg GS, this gave me kind of a headache too, but worked for me.
8th Dec 2020, 2:25 PM
Dr. Adam Szabo
Dr. Adam Szabo - avatar
0
Avalon I'm sorry, the task was to print the last variable of a list define by the input of the user
31st Aug 2020, 2:27 PM
Greg GS
Greg GS - avatar
0
Avalon Maybe I'm wrong but I think that the answer you propose me will make the same error than me for the second test. The input of the second test is 42 and with your solution, the output will be 2 no ? The solution wanted is 42.
31st Aug 2020, 2:34 PM
Greg GS
Greg GS - avatar
0
Avalon I'm trying. The problem is to print last element of the list. But the test 2 has only the number 42 in the list. So when I'm using my code or your code, it works with all the test who as multiples number in it. But for the test 2, instead of print 42 who is the solution wanted, the code print 2.
31st Aug 2020, 2:59 PM
Greg GS
Greg GS - avatar