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:

Examiner Feedback: “Students fail to use scaffolding and comments effectively” and “Students struggle to plan, break down and structure programs.” Students who plan their programs before coding consistently score higher marks.

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

  1. Read the task carefully — understand exactly what the program needs to do
  2. Break it into steps — identify the individual actions your program must perform
  3. Write comments for each step — describe what each part of the code should do
  4. Fill in the code — write the Python code underneath each comment
Why This Matters for Your Exam The Pearson Edexcel GCSE mark scheme rewards clear program structure. Comments show the examiner your thought process, which can earn you marks even if your code contains minor errors. A well-commented program with a small bug will often score higher than an uncommented program that happens to work. Comments prove you understand the problem, even when your syntax is not perfect.

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.

The Task: Create a program that asks for 5 test scores and calculates the average.

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.

The Plan (Comments Only)
# 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
(click "Run Code" to see output)

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.

Complete Solution
# 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))
(click "Run Code" to see output)
Notice: Every single line of code sits directly below its corresponding comment. The examiner can see your plan AND your implementation. If you make a small mistake in the code, the comment shows you knew what you were trying to do — and that can still earn marks.
Key Insight: The comments did not change between Step 1 and Step 2. The plan stayed the same — we just added the code to carry it out. This is the power of comment-first coding: you separate thinking from typing.

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.

Challenge 1: Greeting Generator
Guided

Ask for the user's name and age, then display a personalised greeting.

Expected output example: "Hello, Alex! You are 15 years old."

Your Code
# Ask the user for their name

# Ask the user for their age (as a whole number)

# Create a greeting message

# Display the greeting
(click "Run Code" to see output)
Need a hint?

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.

Challenge 2: Even or Odd Checker
Guided

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"

Your Code
# 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
(click "Run Code" to see output)
Need a hint?

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.

Challenge 3: Times Table Generator
Partially Guided

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

Your Code
# Get the number from the user

# Loop from 1 to 12
    # Calculate the result
    # Display in format: 5 x 1 = 5
(click "Run Code" to see output)
Need a hint?

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

Challenge 4: Password Strength Checker
Partially Guided

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.

Your Code
# 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
(click "Run Code" to see output)
Need a hint?

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.

Challenge 5: Write Your Own Comments First
Open-Ended

This time, you write the comments AND the code. Read the task carefully, plan your steps as comments, then fill in the code.

The Task: A shop needs a program that calculates the total cost of items including a 20% VAT. The program should ask how many items the customer is buying, then ask for the price of each item, calculate the subtotal, add VAT, and display a receipt.

Start by writing your comments (your plan), then write the code underneath each one. This is exactly what you should do in the exam.

Your Code
# Write your comments first, then add code beneath each one

(click "Run Code" to see output)
Suggested comment structure (try writing your own first!)

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.