+ 1

Write a program that takes a list as input and outputs the last element of that list.

List Slices Write a program that takes a list as input and outputs the last element of that list. The input list can be of any size. Here's my code: x = input() elements = x.split() #your code goes here print(x[-1]) This passes all the tests except when the input is 42, in which case it prints 2, rather than 42. The goal is to use list slices.

30th Sep 2021, 10:50 PM
Kevin
2 Antworten
+ 3
It should be elements[-1] instead of x[-1]
30th Sep 2021, 11:18 PM
Simon Sauter
Simon Sauter - avatar
+ 3
@Simon, I'll be honest, I didn't even see that elements existed until you pointed it out. I should take a break lol. Thank you.
30th Sep 2021, 11:39 PM
Kevin