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.)

Python
  1. marks = [4, 7, 5]
  2. total = 0
  3. for mark in marks:
  4. if mark >= 5:
  5. total = total + mark
  6. 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 = 0
for coin in coins:
total = total + coin
print(total)

Variables

coin=—total=—

Step 1. The list of three coins is stored.

Step 1 of 11Called right: 0 of 2

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.

7 of 7 still to sort.

Each edit is made to a working program that adds up marks and prints the total after a for loop.

Exam line: Blank lines and spaces within a line are for readers. Indentation is the part Python reads, so a change to it can stop the program or move a line into a different block.

One working program, two layouts

Inconsistent layoutvsConsistent style

Both versions are accepted by Python and give the same output. Compare the conventions one at a time.

Focus

What the program does

Inconsistent layout

Same output

Consistent style

Same output

The insight

Style changes how the code looks, not what it does. The one exception is the indentation Python requires.

Indentation per level

Inconsistent layout

Two spaces in one block, four in the next

Consistent style

The same amount for every level of nesting (four spaces)

Tabs and spaces

Inconsistent layout

Tabs in some blocks, spaces in others

Consistent style

One or the other, never a mix

Blank lines

Inconsistent layout

Gaps in odd places, or none at all

Consistent style

A blank line between input, processing and output

Spaces within a line

Inconsistent layout

total=total+mark here, total = total + mark there

Consistent style

total = total + mark and [4, 7, 5] every time

Python · Style

?

Reason it through

Why does a consistent style make a program easier to maintain?

Link 1 of 4

First link · your turn

Someone opens a program laid out in one consistent style. What does the layout show them straight away?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

Eduqas Computer Science · Explain

Write it like an exam answer

Sam and Lee wrote different parts of one Python program. Sam’s part is laid out in a consistent style. Lee’s is not.

Explain why Sam’s part is easier to read and easier to maintain than Lee’s. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Point at the layout feature, then say what it lets a person do.

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

1Python 3 treats indentation as syntax; blank lines and spaces within a line are for readers.
2Wrong indentation either stops the program (IndentationError) or moves a line into a different block (a logic error).
3A consistent style uses the same indentation for each level, never mixes tabs and spaces, and uses blank lines and spacing the same way throughout.
4Consistent layout makes code easier to read, and so easier to maintain.

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?
The set of layout conventions a programmer follows when writing code, such as how lines are indented and how white space is used. A consistent style applies them the same way throughout.
What is indentation?
The white space (spaces) at the start of a line that shows which statements belong inside a block, such as the body of an if/elif/else or a for/while.
How does a Python 3 block get marked?
By indenting its statements by the same amount beneath the line that ends with a colon, not by brackets or keywords.
What two things can wrong indentation do in Python?
Raise an IndentationError and stop the program, or place a line in a different block so it runs at the wrong time (a logic error).
What does a consistent indentation style look like?
The same amount of indentation for every level of nesting (four spaces per level is the common Python convention), and no mixing of tabs and spaces.
How does indentation depth help a reader?
Each nested block is indented one level further than the block containing it, so the depth shows the program’s structure at a glance.
What counts as white space that doesn’t change the program?
Blank lines and spaces within a line. Apart from the indentation Python requires, adding or removing them does not change what the program does.
What are consistent blank lines for?
Separating the code into logical sections, such as input, processing and output, so the separate parts are easier to see.
How can spaces within a line be used consistently?
One space either side of an assignment or comparison operator (total = total + mark) and a space after each comma.
Why does a consistent style make code easier to maintain?
Easy-to-read code can be understood later by the original or another programmer, errors are found and fixed more quickly, and changes carry less risk of new errors.
Why does consistent layout help when several programmers share a program?
Code written by different people looks the same, so it can be read in the same way.

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 posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

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.