Session 2 — Playing with Data
Duration: 75 min · Format: live online · Ages: 12–15
Session goal: by the end, students can store many values in a list, loop through them, and compute a total, an average, and the maximum.
Before class — prep (5 min)
- Open Google Colab → New notebook, ready to screen-share. You'll type the list and loop live.
- Have the diagram below ready to share on screen (a list and a loop building a total), and the DataFrame diagram for fast finishers.
- Have students reopen last session's Colab notebook (or open a fresh one) so they can code along.
Agenda
| Time | Segment |
|---|---|
| 0:00 | Hook — one variable per value doesn't scale (5 min) |
| 0:05 | Teach — a list holds many values (13 min) |
| 0:18 | Teach — a loop repeats for every item (15 min) |
| 0:33 | Activity — analyse your own week's data (25 min) |
| 0:58 | Check for understanding (10 min) |
| 1:08 | Wrap-up + homework (7 min) |
0:00 · Hook (5 min)
Ask the class and take a few answers (chat or unmute):
- "Last session you stored one value in a variable. What if you had 500 test scores — would you make
score1,score2… all the way toscore500?"
Let them react, then land it: data science means handling thousands of values at once. Today they learn the two tools that make that possible — a list holds all the values in one place, and a loop processes them in just a few lines.
0:05 · Teach — A list holds many values (13 min)
Explain: a list stores many values in order. Each value has a position called an index, and indexes start at 0, not 1.
Share this diagram and trace the loop visiting each number to build a total:
Type/run this together in Colab:
scores = [12, 7, 25, 9]
print(scores[0]) # 12 (first item)
print(len(scores)) # 4 (how many)
Ask: "Why does scores[0] give 12 and not 7?" (Answer: lists start counting at 0, so index 0 is the first item.)
⚠ Watch for the off-by-one trap: students expect
scores[1]to be the first item. It's actually the second. Counting from 0 is the single most common list mistake — call it out early.
0:18 · Teach — A loop repeats for every item (15 min)
Explain: a for-loop runs the same steps for each item — whether the list has 4 numbers or 4 million. Point out the indentation: the indented line runs once per item.
Type/run this together in Colab:
scores = [12, 7, 25, 9]
total = 0
for s in scores:
total = total + s # add each score to the total
print("Total:", total) # 53
print("Average:", total / len(scores)) # 13.25
print("Highest:", max(scores)) # 25
Walk through one pass of the loop out loud: total starts at 0, then becomes 12, then 19, then 44, then 53.
Ask: "What would happen if we put print("Total:", total) inside the loop, indented?" (Answer: it would print the running total four times, not once.)
⚠ Watch for: Python has handy shortcuts —
sum(scores),max(scores),min(scores)— and students may reach for them straight away. That's fine, but make sure they can also explain how the loop builds the total underneath. That's what makes them a real coder.
0:33 · Activity — Analyse your own data (25 min)
Have students open Google Colab and analyse a real list from their own life. Screen-share your notebook as a model.
Type/run this together in Colab:
sleep = [8, 7, 6, 9, 7, 10, 8]
Then have them:
1. Use a loop (or sum) to print the total and the average.
2. Print the most and least with max() and min().
3. Bonus: count how many nights they slept 8 or more hours using a loop and an if.
Circulate for (or watch the chat for) the classic "biggest" bug. Share this broken code and ask why it only ever prints 9:
scores = [12, 7, 25, 9]
for s in scores:
biggest = s
print(biggest)
Ask: "Why is biggest always the last number?" Then fix it live: biggest is overwritten every loop, so it ends on the last item. To find the real biggest, start biggest = scores[0], then inside the loop if s > biggest: biggest = s. (Or just use max(scores).)
0:58 · Check for understanding (10 min)
Ask these aloud or drop them in the chat. Answer key (for you):
- What is
scores[0]inscores = [12, 7, 25, 9]? →12— lists start counting at 0, so index 0 is the first item. - What does a for-loop do? → Runs the same steps for every item in a list, automatically.
- How do you get the average of a list? →
sum(list) / len(list)— the total divided by how many items.
1:08 · Wrap-up + homework (7 min)
- Ask one student to explain in one sentence why a loop beats writing
score1 … score500. - Homework — Real numbers from your life: collect a real list of numbers (steps per day, minutes of reading, goals scored). In Colab, print the total, average, highest, and lowest — plus one sentence about what you notice. Bring it to Session 3.
Teaching notes
- Correct this misconception: "the first item is index 1." In Python it's index 0 — this trips up almost everyone at first.
- Common coding errors students hit: forgetting to indent the line inside the
forloop (or indenting inconsistently); startingtotalat nothing instead of0; overwriting a variable inside the loop instead of comparing (the "biggest" bug above); dividing by the wrong count. - Fast finishers (extension): it's time for real data. Pandas turns a data file into a DataFrame — a table you can code with. Share this diagram and have them run the code:
```python import pandas as pd
# load a real, public dataset (thousands of rows!) url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv" df = pd.read_csv(url)
print(df.shape) # (rows, columns) df.head() # peek at the first 5 rows print(df["body_mass_g"].mean()) # average penguin mass ```
Explain that real data has gaps — df = df.dropna() removes empty rows, then check df.shape again. Challenge them to print the average of another column, and the count of each species with df["species"].value_counts().
- Low-tech fallback: if devices can't run Colab, work the scores = [12, 7, 25, 9] loop by hand on the shared screen — write the value of total after each pass — then have students trace their own sleep list on paper before typing it up later.
Vocabulary
| Term | Meaning |
|---|---|
| List | Many values stored in order |
| Index | An item's position (starts at 0) |
| Loop | Repeating steps for each item |
| Average / Mean | Total ÷ how many |
| DataFrame | A table of data in Pandas |
Resources
- Google Colab — run your code.
- W3Schools — Python Loops — clear examples.
- Kaggle — Pandas (free course) — the next level for fast finishers.
- Our World in Data — free real datasets to download.
Next session
Session 3 — Your First Prediction: students build a real model that learns a pattern from data and predicts a new value with scikit-learn.