Good programmers don't start by typing code — they start by thinking. Before a single line of Python, you work out the steps to solve the problem. This chapter is about that planning stage: algorithms, flowcharts and pseudocode. Master it and your actual coding becomes far easier and far less buggy.
1Algorithms and pseudocode
An algorithm is a finite, step-by-step set of instructions to solve a problem. A good algorithm is precise (no ambiguity), finite (it ends), and produces the correct result. You write algorithms in plain language. For example, to find the larger of two numbers A and B:
Step 1: Start Step 2: Read A and B Step 3: If A is greater than B, then the larger is A Step 4: Otherwise the larger is B Step 5: Display the larger value Step 6: Stop
Pseudocode is a halfway point between plain English and real code — structured like a program but not tied to any language's exact syntax. It lets you focus on logic:
INPUT A, B
IF A > B THEN
PRINT A
ELSE
PRINT B
ENDIF
- An algorithm is a precise, finite, step-by-step method to solve a problem.
- It must be unambiguous, end after a finite number of steps, and give the correct result.
- Pseudocode is structured, language-independent code that captures the logic before you write real syntax.
2Flowcharts and their symbols
A flowchart is a picture of an algorithm, drawn with standard symbols joined by arrows showing the flow of control. Each symbol has a specific meaning:
| Symbol shape | Meaning |
|---|---|
| Oval / rounded | Terminal — Start or Stop |
| Parallelogram | Input / Output — read data or display result |
| Rectangle | Process — a calculation or action |
| Diamond | Decision — a yes/no question (branches) |
| Arrows | Flow lines — the order of steps |
- A flowchart pictures an algorithm using standard symbols joined by flow-line arrows.
- Oval = Start/Stop (terminal); parallelogram = input/output; rectangle = process; diamond = decision.
- A decision (diamond) has a yes/no question and branches the flow.
3Errors: syntax, logical and runtime
When you write code, three kinds of error can appear. Telling them apart is a frequent exam question and a real debugging skill:
| Error type | What it is | Example |
|---|---|---|
| Syntax error | Breaking the language's grammar rules — the code won't run at all | Missing colon: if x > 5 (no :) |
| Runtime error | Code is grammatically valid but crashes while running | Dividing by zero, using a name that doesn't exist |
| Logical error | Code runs without crashing but gives the wrong answer — the logic is flawed | Using + where you meant * |
Debugging is the process of finding and fixing errors, and testing means running the program with different inputs (including edge cases) to make sure it behaves correctly.
- Syntax error: breaks grammar rules, code won't run (e.g. a missing colon).
- Runtime error: valid code that crashes while running (e.g. divide by zero).
- Logical error: runs fine but gives the wrong answer — only testing catches it.
- Debugging = finding and fixing errors; testing = running with varied inputs.
★ Practical: plan before you code
On paper:
- Write a step-by-step algorithm to find the average of three numbers.
- Draw a flowchart for it using the correct symbols (terminal, input/output, process).
- Write the same logic as pseudocode.
- Classify each: a missing colon, a divide-by-zero crash, and adding instead of multiplying.
Ready for the chapter test?
Answer 5 questions. Score 60% or more to mark this chapter complete.
Start the test →💡 Log in to save your progress and earn the certificate.