Open the app
  1. Home
  2. Lessons
  3. GCSE & IGCSE Computer Science
  4. Writing readable code and from algorithms to programs

Writing readable code and from algorithms to programs

🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.

Code is read far more often than it is written. Clear code is easier to fix, improve and share.

Making code readable

Comments (starting with #) explain what code does and why.
Meaningful identifiers such as total_price instead of tp or x.
Indentation shows the structure of loops, ifs and subprograms (and is required in Python).
White space and blank lines separate sections. A clear layout keeps related code together.

Structural components

Look for these in any program: constants and variables, initialisation (total = 0), assignment, sequence, selection (if), repetition (while, for), iteration over a data structure, data structures (lists), subprograms with parameters, and input/output.

From algorithm to program

Each flowchart or pseudocode part becomes a Python construct:
Process box → assignment. Decision diamond → if or a loop condition. Input/output box → input() or print(). Arrow back up to an earlier step → a loop.
This program adds up the positive numbers among 5 inputs:
total = 0
for count in range(5):
    num = int(input("Number: "))
    if num > 0:
        total = total + num
print(total)
Worked example

The program in step 3 is given the inputs 4, -2, 7, 0, 3. What is output?

  1. Only positive numbers are added: 4, 7 and 3.
  2. 4 + 7 + 3

Answer: 14

Key idea

Comments, meaningful identifiers, indentation and white space make code easy to maintain. Decision symbols become if statements or loop conditions; process boxes become assignments.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.