Slice List - Pro Exercise | Sololearn: Learn to code for FREE!

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 !

8/31/2020 1:53:51 PM

Greg GS

8 Answers

New Answer

+1

1.What is the task? 2. never ever ever never redefine predefined (built-in) function names!!!

+1

try this, it has to work. x=input() print(x[len(x)-1])

+1

Greg GS , can you just make it clear? You said last element of a list. Here you are. What 2, what 4???

+1

Ok then. print(elements[-1:])

+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.

0

Avalon I'm sorry, the task was to print the last variable of a list define by the input of the user

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.

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.