19.3k views
5 votes
Write a program that extracts the last three items in the list sports and assigns it to the variable last. Make sure to write your code so that it works no matter how many items are in the list

User Mbeasley
by
4.5k points

1 Answer

2 votes

Answer:

sports = ["football", "basketball", "volleyball", "baseball", "swimming"]

last = sports[-3:]

print(last)

Step-by-step explanation:

*The code is in Python.

Create a list called sports

Create a variable called last and set it to the last three elements of the sports list using slicing

Print the last

User Xavier Dury
by
5.2k points