What Is Comment-First Coding?
Comment-first coding is a simple but powerful strategy: before you write a single line of Python, you write your plan as comments. Each comment describes one step your program needs to take. Once your plan is in place, you fill in the actual code underneath each comment.
This technique directly addresses one of the most common reasons students lose marks in their GCSE Computer Science exams. The Chief Examiner has repeatedly noted:
Think of it like building a house. No builder starts laying bricks without a blueprint. Comments are your blueprint — they show the examiner (and yourself) that you understand the problem and have a clear plan for solving it.
The Process
- Read the task carefully — understand exactly what the program needs to do
- Break it into steps — identify the individual actions your program must perform
- Write comments for each step — describe what each part of the code should do
- Fill in the code — write the Python code underneath each comment
Comment-first coding also helps you avoid one of the biggest traps in programming: trying to solve the whole problem at once. By breaking the task into small, manageable steps, each step becomes much easier to code. You stop staring at a blank screen wondering where to start, and instead work through a clear checklist.
Worked Example
Let us work through a complete example to see comment-first coding in action.
Step 1: Write the Comments (Your Plan)
Before writing any code, we break the problem down into logical steps and write each one as a comment. This is your plan — your blueprint. Notice how each comment describes what needs to happen, not how to do it in Python.
# Step 1: Create an empty list to store scores
# Step 2: Use a loop to ask for 5 scores
# Step 3: Add each score to the list
# Step 4: Calculate the total of all scores
# Step 5: Calculate the average
# Step 6: Display the result
If you run the code above, nothing happens — and that is exactly right. Comments are ignored by Python. But look at what we have achieved: a clear, step-by-step plan that anyone can follow. An examiner reading this would already know that you understand the problem.
Step 2: Fill in the Code
Now we write the Python code underneath each comment. Each comment tells us exactly what to write. The hard part (thinking about the logic) is already done.
# Step 1: Create an empty list to store scores
scores = []
# Step 2: Use a loop to ask for 5 scores
for i in range(5):
# Step 3: Add each score to the list
score = int(input("Enter score " + str(i + 1) + ": "))
scores.append(score)
# Step 4: Calculate the total of all scores
total = sum(scores)
# Step 5: Calculate the average
average = total / len(scores)
# Step 6: Display the result
print("Scores entered: " + str(scores))
print("Total: " + str(total))
print("Average: " + str(average))
Your Turn
In each challenge below, the comments (your plan) have already been written. Your job is to write the Python code underneath each comment. Start with the guided challenges and work your way up to the open-ended one.
Ask for the user's name and age, then display a personalised greeting.
Expected output example: "Hello, Alex! You are 15 years old."
# Ask the user for their name
# Ask the user for their age (as a whole number)
# Create a greeting message
# Display the greeting
For the first comment, use input() to get the name: name = input("What is your name? ")
For the age, remember to wrap input() in int() to convert it to a whole number.
To create the greeting, join strings together with +. Remember to convert the age back to a string with str() when joining.
Ask the user for a number and tell them whether it is even or odd.
Expected output example: "7 is odd" or "12 is even"
# Ask the user for a number
# Convert the input to an integer
# Check if the number is even using modulus
# Display whether it is even or odd
You can combine the first two comments into one line: number = int(input("Enter a number: "))
The modulus operator % gives the remainder after division. If number % 2 == 0, the number is even. Otherwise, it is odd.
Use an if/else statement to check and print the result.
Ask the user for a number and display its times table from 1 to 12.
Expected output example (for 5):
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
... and so on up to 12
# Get the number from the user
# Loop from 1 to 12
# Calculate the result
# Display in format: 5 x 1 = 5
Use for i in range(1, 13) to loop from 1 to 12. Remember that range() stops before the end value, so you need 13 to include 12.
Inside the loop, calculate result = number * i and then print using: print(str(number) + " x " + str(i) + " = " + str(result))
Check if a password is at least 8 characters long and contains at least one digit. Rate it as strong, medium, or weak.
Rules: Strong = 8+ characters AND contains a digit. Medium = meets one condition. Weak = meets neither condition.
# Ask the user to enter a password
# Check the length of the password
# Check if the password contains at least one digit
# Display the result: strong, medium, or weak
Use len(password) to check the length. Store the result of the check in a boolean variable: long_enough = len(password) >= 8
To check for a digit, you can use a boolean variable and a loop:
has_digit = False
for char in password:
if char.isdigit():
has_digit = True
Then use if/elif/else to check the combinations: both true = strong, one true = medium, neither = weak.
This time, you write the comments AND the code. Read the task carefully, plan your steps as comments, then fill in the code.
Start by writing your comments (your plan), then write the code underneath each one. This is exactly what you should do in the exam.
# Write your comments first, then add code beneath each one
Here is one way you could structure your comments:
# Ask how many items the customer is buying
# Create a variable to store the subtotal
# Use a loop to ask for the price of each item
# Add each price to the subtotal
# Calculate the VAT (20% of the subtotal)
# Calculate the total (subtotal + VAT)
# Display the receipt with subtotal, VAT, and total
Remember: VAT = subtotal * 0.2 and total = subtotal + VAT.
Use round(value, 2) to round money values to 2 decimal places.