Forty index cards land on your table, face down. Each one has a date and a number: the count of items handed in to a school lost-and-found bin on one school day. Forty school days, forty cards, one shoebox that somebody has to empty when it overflows.

The caretaker’s question is not “what is the average”. It is:

“When should I empty it? I would rather not walk over there for three sweaters.”

The task

Round one, on the desk. Answer her question using nothing but the cards, your hands, and the table. Sort them, stack them, line them up, group them by weekday — whatever gets you to an answer you would be willing to say to her face. Write the answer in one sentence, and write down what you did to the cards to get it.

Round two, on the machine. Now make the computer do it. You have variables, input and output, decisions, and loops. Forty numbers. Go.

Round two is where the exploration actually starts.

Round two, honestly

Most people begin like this, because it is the only tool they have:

value1 = 12
value2 = 7
value3 = 19
largest = value1
if value2 > largest:
    largest = value2
if value3 > largest:
    largest = value3
print(largest)

That works. It prints 19. Now do the other thirty-seven, and then answer a second question about the same forty numbers.

Before you type another line, answer these:

  1. How many names have you invented, and can you keep them straight?
  2. Your loop from last week counts perfectly to forty. Can it reach value17? Try it. What stops you?
  3. What would you need — not what is it called, what would you need — for the counting loop and the forty values to meet?

What tends to surface

Two things, usually in this order. First, that forty separate names for forty related values is not merely tedious, it is unworkable — you cannot write a loop over things whose names you invented one at a time. Second, that the pile has structure the cards were hiding: order, days of the week, a shape. Somebody always says “can we not just number them?” That sentence is an index, and it arrives about ninety seconds before anybody says the word.

The caretaker’s question also refuses to be answered by a single number. An average tells you nothing about when. That gap between a statistic and a decision is what the next task is built on.

Where this goes next

The container you needed is named in Lists, read and modified in Working with Lists, and drilled in Lists Practice. Two classes later, a pile of numbers becomes advice somebody can act on, which is The Data Digest. And the outlier cards — the ones with a human explanation — come back in When Code Hurts, because every data pile leaves somebody out.

The answer is not on this page

No list syntax is printed here, and neither is the caretaker’s answer. Your forty cards are not the forty cards in the next room. The container gets invented at your tables, out of frustration, which is exactly how it was invented the first time.

Curriculum connection

A1.5

describe the structure of one-dimensional arrays and related concepts, including elements, indexes, and bounds;

Link to original

A2.3

write algorithms with nested structures (e.g., to count elements in an array, calculate a total, find highest or lowest value, or perform a linear search).

Link to original