Skip to content
AI-grafen
CBuilderProgramming· about 30 min· fundamentals that rarely change· verified 2026-09-20· EN

Plan a program before you code it

Be able to break a problem down into steps and functions before coding.

Prerequisites

Intuition

Beginners start writing code straight away and get stuck. Experienced programmers plan first — often on paper.

The method:

  1. Write what the program should do in one sentence.
  2. Split it into 3–5 steps.
  3. For each step: what goes in, what comes out?
  4. Each step becomes a function.
  5. Code one step at a time and test it before the next one.

Then the fault is never more than one step away.

Code

The task: «A program that reads in exam results and shows how many passed.»

StepInOutFunction
1. Read the resultsfile namelist of numbersread_results(file)
2. Filter the passeslist, thresholdlist of passespasses(results, threshold)
3. Count and showlist, totaltextsummarise(passes, total)
def read_results(file):
    with open(file, encoding="utf-8") as f:
        return [int(line.strip()) for line in f if line.strip()]

def passes(results, threshold=50):
    return [r for r in results if r >= threshold]

def summarise(p, total):
    return f"{len(p)} out of {total} passed ({len(p) / total:.0%})"

results = read_results("exam.txt")
print(summarise(passes(results), len(results)))

Every function can be tested on its own. That is the whole point of the plan.

Mastery means

  • Breaks a problem down into steps and functions before coding
  • Identifies the input and output of every part

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences