Slice List - Pro Exercise
x = input() elements = x.split() #your code goes here list = x[::-1] print(list) 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 PMGreg GS
8 AnswersNew Answer
1.What is the task? 2. never ever ever never redefine predefined (built-in) function names!!!
try this, it has to work. x=input() print(x[len(x)-1])
Greg GS , can you just make it clear? You said last element of a list. Here you are. What 2, what 4???
Ok then. print(elements[-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.
Avalon I'm sorry, the task was to print the last variable of a list define by the input of the user
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.
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.