Lists: Many Values Under One Name · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.
به انگلیسی

Many values, one name

Computing · Programming · ages 15-16
Name ______________________   Date ____________
  1. rainbowColours holds red, orange, yellow, green, blue, indigo and violet. What does rainbowColours[2] give?

    • orange
    • yellow
    • green
  2. What is a list?

    • One value stored under many names
    • A name with no values at all
    • Many values stored under one name
  3. Appending adds the new item to the end of the list.

    Circle one:   True   False

  4. An empty snack list gets "apples", "crackers", "grapes" and "nuts" appended in that order. What seat does "nuts" take?

    Answer: ______________

  5. After rainbowColours[1] = "pink", what sits in seat 1?

    • pink
    • orange
    • red
  6. Why does one list beat twenty separate variables for the same scores?

    • Twenty names run faster
    • One name holds them all, so the set stays tidy
    • Variables cannot hold numbers
  7. A list holds "b", "c" and "d". You insert "a" at seat 0. What seat does "d" sit in now?

    • 3
    • 2
    • 4
  8. A program reads slot 7 of a 7-item list and fails. What is the mistake?

    • The list needs one more push first
    • Slot 7 is invisible until printed
    • Seats run 0 to 6, so slot 7 is past the end
LightMySky · lightmysky.comW1-mt_ipB6kmyK85-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Many values, one name W1-mt_ipB6kmyK85-s1

  1. yellow · Seats count from 0: red is 0, orange is 1, so yellow sits in seat 2.
  2. Many values stored under one name · A list bundles a whole collection under a single name.
  3. True · Append grows the end, so the newcomer takes the next free seat.
  4. 3 · Four appends fill seats 0, 1, 2 and 3 in order, so the last one lands in seat 3.
  5. pink · Assignment rewrites that slot, so seat 1 now holds pink instead of orange.
  6. One name holds them all, so the set stays tidy · A single name keeps the whole set together with zero clutter.
  7. 3 · Inserting at the front pushes every older item one seat up, so d moves from seat 2 to seat 3.
  8. Seats run 0 to 6, so slot 7 is past the end · Seven items fill seats 0 to 6. Reaching for 7 is one too far.
Worksheet · LightMySky