+ 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.
2 Answers
+ 3
It should be
elements[-1]
instead of
x[-1]
+ 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.