Breaking Problems Down

Hard problems are just several easy problems stacked together. Decomposition is the skill of finding the seams.

Take a real request: from our member list, find the average volunteer hours of everyone in Jackson who joined before 2020.

That sounds like a lot. It is actually four small problems you already know how to solve.

1. Filter to members in Jackson.

2. Filter those to members who joined before 2020.

3. Total their hours.

4. Divide by how many there are.

Every step is a pattern from Module 12. None of them is hard on its own.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Four small steps, each one familiar. Add a fifth step that also prints the name of the highest contributor among the matches.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

✦ When you feel stuck

Stuck almost always means the problem is still too big. Say it out loud in plain English, then split the sentence at every 'and' and every 'then'. Each fragment is usually one loop or one condition.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Edge Cases and Correctness →
← Back