GCSE · Computer Science · Eduqas · Spec C500QS

Refining code during development

Your program runs and prints something. Job done? Not even close: it can run perfectly and still do the wrong thing, or be a nightmare to read.

Computer Science · Refining code

It runs. But does it do what was asked?

A till program should do three things with the basket [4, 7, 5]: (1) add up every price; (2) take 2 off if the total is over 10; (3) print how many items were bought, then the total. Run each version, check the output against those requirements, then choose a fix for the marked line.

Python
  1. prices = [4, 7, 5]
  2. total = 0
  3. for p in prices:
  4. total = p
  5. if total > 100:
  6. total = total - 2
  7. print("Items:", 0)
  8. print("Total:", total)

Every output shown is what Python prints when it runs this exact code. The basket prices are in pounds.

Computer Science · Reviewing code

Which review question is this?

Pick a finding, then pick the review question it answers.

Still to sort

How well it works (0)

Does it run all the way through and give correct results?

Where the line is: The program does try to do the job but gets the result wrong, or stops before it finishes. That is mainly about how well it works.

How readable it is (0)

Could someone else follow it and look after it? Think comments, program layout, identifiers and naming conventions.

Where the line is: The finding is about how the code looks or is named, not about what it does.

Whether it meets the functional requirements (0)

Does it do everything the requirements ask it to do?

Where the line is: The requirements ask for something and the program leaves it out. That is mainly about the functional requirements.

8 of 8 still to sort.

A reviewer has made eight notes about one program. Decide which of the three questions each note answers.

Computer Science · Subprograms

Write it once, call it twice

This program works out the area of two rectangles by writing the same three lines twice: width = 5 length = 3 print("Area:", width * length) width = 6 length = 2 print("Area:", width * length) Refactor it so the repeated code is written only once. Fill in the missing steps.

  1. # The same sum is written out for every rectangle; only the two numbers changeStart by spotting the repetition. The parts that change (the two numbers) are what will become parameters.
  2. missing step
Which line is step 2?

Computer Science · Functions and procedures

Follow the value through the call

Call each marked step in your head before the table shows it.

The main program calls one function and one procedure. Nothing is run here: every value is the lesson's. Commit to each marked step before it appears.

def add_postage(cost):
new_cost = cost + 3
return new_cost
def show_total(amount):
print("Pay: £" + str(amount))
basket = 12
bill = add_postage(basket)
show_total(bill)

Variables

basket=12

Step 1. basket is given the value 12. The def lines only describe the two subprograms; nothing inside them happens until the main program calls them. This first step is worked for you.

Step 1 of 7Called right: 0 of 4

The same program, two versions

One large single-block programvsThe same program divided into subprograms

Read across each row, then read the because underneath.

Focus

Reading it

One large single-block program

One very large program to read from top to bottom.

The same program divided into subprograms

Small chunks of code, each one easier to read.

The insight

It is much easier to read small chunks of code than one very large program. That is the readability benefit.

Finding and fixing mistakes

One large single-block program

A mistake could be hiding anywhere in a lot of code.

The same program divided into subprograms

Each subprogram is a small amount of code to look through.

Making and testing a change

One large single-block program

Changing something can mean hunting through the whole program, and the change could affect the rest of it.

The same program divided into subprograms

The change is made and tested in one place, and the rest of the program is not affected.

Several programmers working at once

One large single-block program

It is one block of code, so the work is not divided up.

The same program divided into subprograms

Different programmers can write different subprograms at the same time.

Repeated code

One large single-block program

The same code may be written out again and again.

The same program divided into subprograms

The code is written once in a subprogram, then called whenever it is needed.

Eduqas Computer Science · Exam practice

Write it, then mark it

x = 120 y = 5 print(x / y) x = 90 y = 6 print(x / y)

The listing works out a speed from a distance in metres and a time in seconds. It works, but it is hard to read and it repeats code. Describe two ways it could be improved so that it is easier for someone else to read and maintain, then explain one benefit of putting the repeated lines in a subprogram. [4 marks]

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

Exam line: Name the change you would make to this listing, then say what it improves.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

A program that runs isn't finished. Here's how you make it better.

What you need to know

  • Refining code means finding improvements and making them. A program that runs is not automatically finished.
  • Reviewing code checks how well it works, how readable it is and whether it meets the functional requirements.
  • Have a goYour mate says: 'It ran, so it's done!' Name one of the three review checks that 'it ran' doesn't cover.

    How readable it is, or whether it meets the functional requirements.

    Running shows the program did something. It can still be hard to read, or leave out something the requirements ask for.

  • Review against the functional requirements to see what the code doesn't do yet, then adapt it step by step.
  • Improving code may mean simplifying logic, breaking large sections into subprograms, or correcting errors.
  • Readable, maintainable code lets others understand it and work with it; comments, program layout, identifiers and naming conventions all help.
  • Have a goA program keeps a customer's age in a variable called x. Suggest a better identifier.

    customer_age, or any clear name that says what the variable holds.

    A name that says what the variable holds helps anyone who reads or maintains the code understand it easily.

  • Modularity is breaking software into independent, self-contained modules; in structured programming these are subprograms, each doing one specific task.
  • Write repeated code once in a subprogram, then call it whenever it is needed.
  • More modular code brings readability, easier testing, easier maintenance, faster development time and reduced repetition.
  • A function differs from a procedure because it returns a value to the main program, using a return statement.
  • Have a goA subprogram prints 'Hello' on the screen and has no return statement. Function or procedure?

    A procedure.

    Printing is not returning: nothing is sent back to the main program, and returning a value is what makes a function different.

  • Parameters hold the values a function needs, as local variables; the arguments in the call are passed in through them.

The big picture

Working code isn't finished code. Refining means reviewing a program for how well it works, how readable it is and whether it meets the functional requirements, then improving it step by step. Dividing it into subprograms (functions and procedures, with parameters, arguments and return values) makes it easier to read, test, maintain and develop.

Key points

1Run it, check the output against the functional requirements, change one thing, then run it again.
2Good practice is for the next person: whoever has to read, use or maintain your code in the future.
3A subprogram is designed to do one specific task, so repeated code becomes one definition plus calls.
4Arguments go in at the call, parameters receive them as local variables, and a return statement sends a value back.
5A function returns a value to the main program; that is what makes it different from a procedure.

Worked example

Problem

This program should print the larger of two scores, 8 and 5. It prints 5. Refine it. score_one = 8 score_two = 5 if score_one < score_two: print(score_one) else: print(score_two)

⚠ Watch out

Thinking that if a program runs, it is finished. A program can run and still miss something the functional requirements ask for, or be hard for anyone else to read.

🧠

Memory hook

Three questions before you say 'done': does it WORK, can others READ it, and is it what was REQUIRED? If it only runs, it's only a draft.

✓

Check yourself

Without looking back: say the three questions a review asks, then pick a program you have written and name one change you would make to it next.

Flashcards

(13)
What does refining code mean?
Finding improvements and making them: reviewing the code, then adapting it step by step so it meets more of the functional requirements.
What three things does reviewing code check?
How well it works, how readable it is, and whether it meets the functional requirements.
Name three ways code can be improved.
Simplifying logic, breaking large sections of code into subprograms, and correcting errors.
Why should code be readable and maintainable?
So that other people can understand it and work with it easily.
Which good programming practices make code easier to read?
Comments, program layout, identifiers and naming conventions.
What is modularity?
Breaking software into independent, self-contained units or modules.
What is structured (modular) programming?
Dividing a program into smaller subprograms, each designed to do one specific task clearly and effectively.
How do subprograms reduce repeated code?
The code is written once in a subprogram, then called whenever it is needed.
Name the five benefits of improving modularity.
Code readability, easier testing, easier maintenance, faster development time and reduced repetition.
How is a function different from a procedure?
A function returns a value or values to the main program.
What do parameters do?
They define the data values that must be passed to a function when it is called, and are treated as local variables inside it.
How do you call a function, and where do the arguments go?
Write its name followed by the arguments; they are passed into the function via the parameters.
When does a function need a return statement?
When it is going to return a value to the main 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 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.