GCSE · Computer Science · OCR · Spec J277
Maintainability: indentation
Two programs. Same words, same order, same score. One of them tells someone who failed "Well done!". The only difference? Four spaces.
Computer Science · Program layout
Same words, different program
Two Python programs. Same words, same order. Only line 11 has lost its indent. Step through both and watch which lines run.
score is 35, so the if test is False. Before you press Next: what do you think each version prints?
1 # Version A2 score = 353 if score >= 50:4 print("You passed!")5 print("Well done!")6 print("Results sent")7 # Version B8 score = 359 if score >= 50:10 print("You passed!")11 print("Well done!")12 print("Results sent")
Variables
Output
Step 1: Version A starts. score is set to 35.
Press Next and watch which lines light up. The output box keeps a running record, marked A or B.
Layout and maintainability
Reason it through
Why does a consistent, logical layout make a program easier to maintain?
First link · your turn
The code is laid out consistently and logically, with every selection block indented. What does that do for another programmer reading it?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A few spaces at the start of a line can change what a program does, and decide whether anyone can fix it later.
What you need to know
- Maintainability is how easily maintenance jobs, such as correcting errors, can be done on code.
Have a goTwo programs do the same job. One is a nightmare to correct when something goes wrong. Is that a problem with its speed or its maintainability?
Its maintainability.
Maintainability is about how easily maintenance like correcting errors can be done. How fast the program runs is a different question entirely.
- A consistent, logical layout makes code much easier for other programmers to understand.
- Indentation, starting lines further in from the left margin, is a vital part of that layout.
- In Python, indentation is part of the syntax: it decides how the program is executed.
- Python knows which lines belong to an if block because they are indented underneath it.
Have a gox is 1. Under the line if x > 3: sits print('big'), indented. Below that is print('done'), not indented. What gets printed?
done
Only the indented line belongs to the if, and the test is False, so it's skipped. print('done') isn't in the block, so it runs whatever the test says.
- Indenting selection blocks is good layout. In Python, a program whose if block has no indented lines won't run.
- Un-indent one line from inside a block and the program may still run, but do something different.
Have a goYour friend un-indents a line inside an if block. The program still runs. "Told you indentation doesn't matter!" What have they missed?
That line has left the block, so it now runs even when the condition is False.
No error doesn't mean no change. The program runs, but it behaves differently, because the line no longer belongs to the if.
- In some other languages indentation isn't required, but code without it is harder to read.
- Skip good layout and code can become difficult to maintain or fix, and other programmers may not understand it.
- Even the person who wrote the code may struggle to follow it after time away.
The big picture
Maintainability is how easily maintenance, such as correcting errors, can be done on code. A consistent, logical layout makes code much easier for other programmers to understand, and indentation is a vital part of it. In Python, indentation is part of the syntax: it decides which lines belong to a selection block, and a program whose if block has no indented lines won't run. In some other languages it isn't required, but code without it is harder to read, harder to maintain, and harder even for its author to follow later.
Key points
Worked example
Problem
A Python program has five lines. Line 1: mark = 72. Line 2: if mark >= 70: Line 3, indented by 2 spaces: print('Grade A'). Line 4, not indented: else: Line 5, indented by 8 spaces: print('Grade B'). Does it run? What does it print? And how would you improve its layout?
⚠ Watch out
Thinking indentation is just for neatness. It feels true if your code has run fine without it. But in Python, indentation decides which lines belong to a block, so moving one line can change what the program does. Elsewhere, leaving it out still makes code harder to read and maintain.
Memory hook
In Python, the spaces decide what runs. In every language, the spaces decide who can follow it.
Check yourself
Explain to a friend how two Python programs with exactly the same words in the same order can print different things. Then explain why indentation still matters in a language that doesn't need it.
Flashcards
(9)What is maintainability?
Why should a program have a consistent, logical layout?
Which part of program layout is described as vital?
In Python, what is indentation part of?
How does Python tell which lines are inside an if block?
Python: what happens if a selection block has no indented lines?
In a language that doesn't require indentation, what happens if you leave it out?
A line inside a Python if block is moved back to the left margin. What changes?
Three consequences of not following good layout?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.