+ 2

List Slices exercise - [SPOILER]

Hey all, I've been stuck on an exercice, I have the good answers but not in the good format. ### The code ### x = input() elements = x.split() print(elements[-1:]) # Input: 8484 1 88 # output: ['88'] The answer expected is 88 but without [' '] Anyone, know what I'm missing? Thanks

21st Apr 2021, 4:12 PM
Da Silva Miguel
Da Silva Miguel - avatar
7 Respostas
+ 6
drop the ':' in print(elements[-1:]) so its: print(elements[-1])
21st Apr 2021, 4:17 PM
Slick
Slick - avatar
+ 3
Really? Oh c'mon! >.<
21st Apr 2021, 4:18 PM
Da Silva Miguel
Da Silva Miguel - avatar
+ 2
lol what your code says is to print a list containing all values from the last value on. So it prints a list with the last value in it. When you call it without the ':' you are referencing the actual value
21st Apr 2021, 4:20 PM
Slick
Slick - avatar
+ 1
Yeah I though of that, but didn't think of removing ' : '
21st Apr 2021, 4:28 PM
Da Silva Miguel
Da Silva Miguel - avatar
0
You can actually do it in 2 lines of code I found, all you need to do is declare the input: x = input() then print it like this: print(x[-1])
12th Mar 2022, 1:16 PM
Charleston Tate
Charleston Tate - avatar
0
x = input() elements = x.split() print(x[-2:])
5th Jul 2022, 6:43 AM
Zocimo Orozco Valencia
0
#your code goes here x = input () print(x[-1])
3rd Oct 2023, 12:11 PM
DEBORAH ADJEI KYEM
DEBORAH ADJEI KYEM - avatar