CurriculumAlgorithmic Thinking in Python, for KidsTracking patterns: max, min, and count

Max, Min, and Counter Patterns in Python Loops

Three loop shapes with names — recognise them on sight instead of reinventing them each time.

Lesson 1 of 4PROAges 10+
See what PRO unlocks →

Tracking patterns: max, min, and count

You've already written loops that carry a value forward — a running total. There are two more shapes just as common, and they all have names.

Max-tracking: start with a 'best so far' guess, then update it only when something BIGGER shows up.

scores = [40, 85, 12, 90, 33]
highest = scores[0]
for s in scores:
    if s > highest:
        highest = s
print(highest)

Output

90

Notice the shape: ONE box (highest), a loop, an if that only updates it SOMETIMES. That shape is the whole pattern — the rest is just what you're comparing.

Min-tracking is the exact same shape with the comparison flipped — smaller instead of bigger.

prices = [80, 20, 55, 15, 90]
lowest = prices[0]
for p in prices:
    if p < lowest:
        lowest = p
print(lowest)

Output

15

Counting is a third shape: start a counter at 0, and add 1 each time something passes a test — never add the VALUE, just count how many qualify.

hoard = [10, 200, 5, 300, 45, 8]
count = 0
for v in hoard:
    if v > 100:
        count = count + 1
print(count)

Output

2

All three patterns walk a list ONCE, carrying one value forward. Once you recognise which one a problem needs, you don't have to invent the shape from scratch — you already know it.

Check your understanding

You need to find the SMALLEST value in a list of temperatures. Which pattern fits?

  • Min-tracking — start with a 'lowest so far' guess, update when something smaller shows up
  • The counter pattern — count how many temperatures there are
  • Max-tracking, since it's basically the same idea

Why: Min-tracking. It's the pattern built specifically for 'find the smallest' — start with a guess, and only update when something smaller actually shows up. Max-tracking asks the opposite question, and counting asks a completely different one.

hoard = [10, 200, 5, 300, 45, 8]. Using the counter pattern to count values over 100, what's the final count?

count = 0
for v in hoard:
    if v > 100:
        count = count + 1
  • 2 — only 200 and 300 are over 100
  • 500 — the counter pattern adds up the qualifying VALUES, not how many there are

Why: 2. Only 200 and 300 pass the v > 100 test, and the counter pattern adds exactly 1 each time that happens — never the value. count = count + 1 is a different move from total = total + v, even though both carry a running value forward through the loop.

What you'll practice

scores = [40, 85, 12, 90, 33]. Find the HIGHEST score by tracking it as you go: start with the first score as your best guess, then compare every OTHER score against it, updating whenever you find something bigger. Print the final highest score — 90.

Unlock this lesson with PRO →

More from this topic

Tracking patterns: max, min, and count is one lesson inside Algorithmic Thinking in Python, for Kids — see the full lesson order and what the whole topic covers.

View the full topic →