+ 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
7 Antworten
+ 6
drop the ':' in print(elements[-1:])
so its:
print(elements[-1])
+ 3
Really? Oh c'mon! >.<
+ 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
+ 1
Yeah I though of that, but didn't think of removing ' : '
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])
0
x = input()
elements = x.split()
print(x[-2:])
0
#your code goes here
x = input ()
print(x[-1])