Unit 3 · Programming 2 · Lesson 3.10 · Lab

Lab: Gradebook Day

Read a set of scores into a list, then report the high, the low, the average, and how many passed. One program that uses every list skill from this week — and one you’ll rebuild with procedures later.

Big Idea 3 — Algorithms & ProgrammingLab · 10 points

Before this lab

No reading — build. Keep 3.7 (append), 3.8 (traversal), and 3.9 (max / min / average / count-if) open. Everyone builds the same spec today — you’ll refactor it in 3.15.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

End of Week 2 in Programs. You pull the week together: build a list, traverse it, and run all four canonical algorithms on it. Keep your code — in 3.15 you’ll rebuild this exact program using procedures, and the difference will be dramatic.

2

The Brief

Write a program that reads several test scores into a list, then prints a small report about them.

Your report must show

□ The highest score (max).

□ The lowest score (min).

□ The average (sum ÷ how many).

□ How many passed (count-if, score ≥ 60).

Requirements

□ A purpose sentence comment at the top.

□ Read scores into a list (append in a loop, or a fixed list to start).

□ Use a traversal for each statistic (initialize max/min to the first element, not 0).

□ Print the four results clearly with f-strings.

3

The Model

Copy the shape. This is one traversal doing sum and count, plus max/min tracked alongside:

Python — skeleton

# Reports high/low/avg/passed for a class.
scores = [88, 92, 75, 60, 45]
total = 0
passed = 0
hi = scores[0]
lo = scores[0]
for s in scores:
    total = total + s
    if s > hi: hi = s
    if s < lo: lo = s
    if s >= 60: passed = passed + 1
avg = total / len(scores)
print(f"high {hi}, low {lo}, avg {avg}, passed {passed}")

What each part is doing

# purpose: what + why
# the data as a list
# four accumulators,
# initialized BEFORE the loop
# max/min start at a REAL
# value, not 0
# one traversal...
# ...updates all of them
# keep the larger
# keep the smaller
# count-if for passing
# average = sum / count
# use them all, after

Hover or tap a line to light its twin. One loop, four accumulators — that’s the efficient way. For this data: high 92, low 45, avg 72.0, passed 4.

4

Try It — Check Your Report

Enter a list of scores and see the report your program should produce. Compare it to your output — if they differ, you’ve found a bug (often a max/min initialized to 0).

scores:
Presets:
5

What You Turn In

Three things

□ The working program (reads a list, prints all four statistics correctly).

□ Your purpose sentence at the top.

□ One sentence naming which statistic was trickiest to get right and why — most students say max or min, because of the initialization.

Save this program somewhere safe. In 3.15 you’ll rebuild it with procedures and see your messy main program shrink to about five readable lines.

6

How to Work

One statistic at a time

Get sum and average working first — they’re the friendliest. Then add the passing count. Save max and min for last, and test them on the “all failing” and a negative-heavy list so the initialization bug can’t hide. Print each statistic as soon as it works rather than waiting to wire up all four.

Solo or paired — if you pair, swap every 10 minutes, and both of you must be able to explain why max starts at scores[0].

7

Challenge Tier

If you finish early

Read the scores from the user with append in a loop instead of a fixed list, stopping when they type done. Or add a letter-grade breakdown: count how many A’s, B’s, and C’s using the elif chain from 2.13 inside your traversal — four more count-if accumulators, same pattern.

8

Connections

Uses all of Week 2 — lists (3.6), append (3.7), traversal (3.8), and the four algorithms (3.9).
Next in 3.11 — procedures. You’ve been calling len() and print() all along; now you learn what a procedure really is.
Returns in 3.15 — you rebuild this exact gradebook with your own procedures, and the main program becomes five lines.
Returns on the exam — multi-accumulator traversal (“what does this report?”) is a classic longer MCQ. If you built it, you can read it.
← 3.9 Canonical List Algorithms