← Back to course
Code Crew G4 / Week 02 / Crew Quest
6/6
Week 02 Β· Lists

Crew Quest

Crew Quest: Index Card Shelf
// Many values, one name
⏱ about 15 min

Crew Quest: Index Card Shelf

It is quiet time on Beacon Station. Raven lays five cards on the table, face down. "This is our cargo list," she says. "What do you notice about how I numbered them?"

Rocket looks at the small numbers under each card. "Zero, one, two, three, four. Python style!"

Nova hovers above the cards and glows softly. "Let's play. Someone calls an index, and someone else flips that card." Rocket rubs his hands together. "Let's see what happens!"

  1. A list keeps many values in order under one name.
  2. Index 0 is the first item. Index -1 is the last item.
  3. len counts the items. The last index is one less than len.
  4. You can change an item with an index, like cargo[1] = "rice".
  5. append adds a new item to the end of a list.
β—‡ INDEX CARD SHELF
You need five scrap cards and a pencil.
Write a space supply on each card, like water or tape.
Lay them in a row. Write 0, 1, 2, 3, 4 under them.
Your partner calls an index, like cargo[3]. Flip that card and read it.
Try cargo[-1] too. Then add a sixth card with append.
shelf = ["water", "tape", "rope", "oats", "lamp"]
shelf.append("gloves")
print(shelf[-1])
print(shelf[3])
First line on the screen
Second line on the screen
BONUS RECAP
  • Read the question.
  • Tap your answer.
A list has 5 items. What does len give?
Which index is the last item of any list?
What does append do?

Wonderful week, Crew Engineer! Next week, a loop will visit every item in a list for you.

← Friday