GCSE · Computer Science · Eduqas · Spec C500QS
Consistent programming style
Nudge one line in a working Python program and it refuses to run. Nudge another and it gives the wrong answer. Add a blank line and nothing. Which spaces matter?
Python · Indentation
Move one line, break the program
This short program adds up the marks that are 5 or more. Switch the indent guides on and see how deep each line sits. Then press Run, read what Python says, and choose the fix for the line it points at. (The comment on the last line tells you how many spaces it starts with.)
- marks = [4, 7, 5]
- total = 0
- for mark in marks:
- if mark >= 5:
- total = total + mark
- print(total) # 2 spaces
Messages checked against Python 3.13. Nothing here runs live: every message and output is written in advance.
Python · Wrong block
Predict what gets printed
No error message this time. Call each printed line before it appears.
This loop should add up three coins and show the total once. Call what appears on the screen before it does.
coins = [2, 5, 1]total = 0for coin in coins:total = total + coinprint(total)
Variables
Step 1. The list of three coins is stored.
Watch which line the program is on, and the values of coin and total.
Python · What changes what
Which edits matter?
Pick an edit, then choose what it does to the program.
Still to sort
Only readability changes (0)
The program does exactly what it did before.
Where the line is: If the result is identical, it belongs here, even though the code looks different.
Runs, but does something different (0)
No error message, but a line is in a different block (a logic error).
Where the line is: The program still runs, so Python has nothing to complain about.
Stops the program running (0)
Python refuses the indentation.
Where the line is: The program does not start running at all: Python reports an error first.
Each edit is made to a working program that adds up marks and prints the total after a for loop.
Python · Style
Reason it through
Why does a consistent style make a program easier to maintain?
First link · your turn
Someone opens a program laid out in one consistent style. What does the layout show them straight away?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
In Python, some spaces change what your program does. Others only change how easy it is to read.
What you need to know
- A programming style is the set of layout conventions you follow. Consistent means applying them the same way throughout the program.
- Indentation is spaces at the start of a line. It shows which statements belong inside a block, like an if or for body.
- In Python 3, indentation is syntax. A block is the lines indented by the same amount beneath a line ending in a colon.
Have a goYour classmate says: 'Python ignores indentation. It's only there to look neat.' Are they right?
No. In Python 3 indentation is syntax: it marks which lines form a block.
It looks like layout, but Python uses indentation instead of brackets to mark blocks, so changing it can change the meaning or stop the program.
- Wrong indentation can raise an IndentationError, or move a line into a different block so it runs at the wrong time: a logic error.
Have a goAli's program stops with an IndentationError. Bea's runs but prints the wrong total because a line is in the wrong block. Whose gets an error message?
Only Ali's. Bea's layout is valid, so Python has nothing to complain about.
A line in a different block is still valid Python, so there is no message. Only the wrong result gives it away.
- Use the same indentation for every level. The common Python convention is four spaces per level.
- Don't mix tabs and spaces in indentation. Python 3 refuses indentation that mixes them inconsistently.
- Indent each nested block one level further than the block containing it, so depth shows the structure at a glance.
Have a goWith four spaces per level, how many spaces start a line inside an if that sits inside a for loop?
Eight: four for the for body, then four more for the if body.
Each nested block goes one level further in than the block containing it, so the levels add up (4 + 4) instead of staying at 4.
- Other white space, like blank lines and spaces within a line, doesn't change what the program does. Only Python's required indentation does.
- Consistently use blank lines to split input, processing and output, and spaces around operators and after commas.
- Consistency makes code easier to read and so easier to maintain, including when several programmers work on one program.
The big picture
A programming style is the set of layout conventions you follow when writing code, such as how lines are indented and how white space is used. In Python 3, indentation is syntax, so the wrong amount can stop the program or move a line into the wrong block. Other white space only affects readability, and a consistent style makes code easier to read and so easier to maintain.
Key points
Worked example
Problem
A program reads a name and a mark, sets result to "Pass", changes result to "Try again" if the mark is below 5, then prints the name and the result. It is written like this (| marks the end of each line): name=input("Name: ") | mark=int(input("Mark: ")) | result="Pass" | if mark<5: | [8 spaces]result="Try again" | print(name) | print(result). Rewrite it in a consistent style without changing what it does.
⚠ Watch out
Treating all white space the same. Layout is not just decoration: wrong indentation can stop the program or move a line into the wrong block. But blank lines and spaces within a line do not change what it does.
Memory hook
Indentation is the program's skeleton; blank lines and spaces are its clothes. Move a bone and the program breaks or limps along doing the wrong thing. Change the clothes and it still walks exactly the same way.
Check yourself
Cover the page. A classmate says: 'In Python, spaces are just decoration.' Give them one change to the spaces that does alter what the program does or stops it, and one that does not.
Flashcards
(11)What is a programming style?
What is indentation?
How does a Python 3 block get marked?
What two things can wrong indentation do in Python?
What does a consistent indentation style look like?
How does indentation depth help a reader?
What counts as white space that doesn’t change the program?
What are consistent blank lines for?
How can spaces within a line be used consistently?
Why does a consistent style make code easier to maintain?
Why does consistent layout help when several programmers share a program?
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 Eduqas GCSE Computer Science topics
- Abstraction
- Analyse a set of requirements
- Authentication management routines
- Comparing approaches to requirements
- Creating and extending Python 3 functions/methods
- Creating and extending Python 3 libraries
- Decomposition
- Designing a testing strategy
- Explaining test outcomes
- File handling: open a file
- File handling: read into a variable
- File handling: read into an array
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 16 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.