You've learned that a list stores an ordered collection of values, that indexing starts at 0, that -1 reaches the last item, and that len() tells you how many items there are. Now put all four ideas to work.
A small online shop keeps its product names in a list. You'll pull out the first and last product and report how many products there are in total.
Your tasks
Given this starting value:
products = ["keyboard", "mouse", "monitor", "webcam"]
1. Store the first product in a variable called first using index 0
2. Store the last product in a variable called last using a negative index (so it works no matter how long the list is)
3. Store the number of products in a variable called count using len()
4. Print first, then last, then count — each on its own line
Expected output
Constraints
- Use index
0 to get the first item
- Use a negative index (
-1) to get the last item — do not hard-code products[3]
- Use
len() to count the items — do not type the number 4 directly
- Do not change the
products list