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.
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.
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.
Write a program that reads several test scores into a list, then prints a small report about them.
□ The highest score (max).
□ The lowest score (min).
□ The average (sum ÷ how many).
□ How many passed (count-if, score ≥ 60).
□ 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.
Copy the shape. This is one traversal doing sum and count, plus max/min tracked alongside:
# 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}")
# 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.
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).
□ 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.
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].
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.
len() and
print() all along; now you learn what a procedure really is.