Practice Challenge: Combining Python's Loop Patterns

Max-tracking, counting, and searching — all three, on one list, composed without new tricks.

  • Lesson 4 of 4
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

The Dragon's Full Hoard Report

  1. The dragon: You know three named patterns now: max/min-tracking, the counter, and search-with-a-flag. The challenge ahead uses all three, on the same list.

  2. The dragon: Each pattern keeps its OWN box and its OWN loop — running three patterns over one list is just running them one after another.

    example.pyPython 3
    loot = [15, 200, 8]highest = loot[0]for v in loot:    if v > highest:        highest = vcount = 0for v in loot:    if v > 50:        count = count + 1print(highest, count)
    Output200 1
  3. The dragon: Nothing new here — just choosing the right pattern for each part of the question, and not letting one loop's box get confused with another's.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 2

    You need BOTH the highest value in a list AND how many values are over 50. Can one single loop do both at once?

    • Yes — a loop can update more than one box per pass, as long as each box has its own checkCorrect
    • No — each pattern needs its own completely separate loop

    Why: Yes — one loop CAN do both, updating highest and count in the same pass, since neither check depends on the other. Separate loops (one per pattern) are often easier to read and are exactly what this topic's levels use, but combining them into one pass is also correct.

  2. Question 2 of 2

    loot = [15, 200, 8, 45, 200, 3]. Using the counter pattern for values > 50, what's the count?

    question.pyPython 3
    count = 0for v in loot:    if v > 50:        count = count + 1
    • 2 — only 200 and 200 are over 50Correct
    • 1 — duplicate values only count once

    Why: 2. The counter pattern just checks each item independently — it doesn't track which VALUES it's already seen, so two items with the same value both count separately if they both pass the test. loot has two 200s, and both are over 50.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    loot = [15, 200, 8, 45, 200, 3]. Find the highest value (max-tracking) AND count how many values are over 50 (counter). Print the highest, then the count.

  2. +2

    PracticeTwo more, on your own

This lesson is part of PRO.

PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.

Unlock this lesson with PRO

Stuck three times? The game offers the answer — unasked.