GCSE · Computer Science · Edexcel · Spec 1CP2
Reading, writing, analysing and refining programs
The first scheduler lets you add one game review, then stops. Which requirement does it miss?
Computer Science · Refining code
Does the stream scheduler do what it must?
Requirement: keep adding game reviews until the stream is full, then output every game name. Step through version 1, then the refined version 2. The values are made up for the example.
Version 1 runs fine and stops. Which requirement has it not met by the end?
1 # VERSION 1 - original2 stream_seconds = 15003 total_time = 04 game_names = []5 game_names.append(input('Game: '))6 total_time = total_time + int(input('Seconds: '))7 print(game_names[0])8 # VERSION 2 - refined9 stream_seconds = 150010 total_time = 011 game_names = []12 while total_time < stream_seconds:13 game_names.append(input('Game: '))14 total_time = total_time + int(input('Seconds: '))15 for i in range(len(game_names)):16 print(game_names[i])
| stream_seconds | total_time | game_names |
|---|---|---|
| 1500 | 0 | [] |
Output
Step 1: Version 1 sets up its variables. The stream is 1500 seconds long and nothing has been reviewed yet.
Step through the trace — every value is the lesson’s, not run by the page.
Computer Science · Functional requirements
Input, process or output?
Pick a requirement from the stream scheduler, then pick the category it belongs to.
Still to sort
Input (0)
Data going into the program.
Where the line is: If the program is receiving a value from the user, it's an input. If it's doing something to a value it already has, it's a process.
Process (0)
What the program does with data.
Where the line is: A process works on data inside the program. Nothing is typed in and nothing is shown to the user.
Output (0)
Data coming out of the program.
Where the line is: If the user gets to see it, it's an output.
A functional requirement says what a program must do. Split each one into an input, a process or an output.
Computer Science · Algorithms
Trace table — dry run the code
Follow total = calculate(num1, num2). The body of calculate is just an example.
Ready when you are — step through one line at a time.
Predict, then check
Both versions do exactly the same job.
Version A: # convert minutes to seconds def minutes_to_seconds(stream_minutes): return stream_minutes * 60 Version B: def f(x): return x*60 A new programmer has to improve this code. Which version could they work with first?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Read your code against its requirements, find what it doesn't do yet, then make it better.
What you need to know
- Functional requirements define what a program must do, split into inputs, processes and outputs. Code is written to meet them.
Have a goA stream scheduler has to check a duration is between 20 and 40 minutes. Is that an input, a process or an output?
A process.
It works on a value the program already holds. An input arrives from the user, and an output is shown to them.
- Reviewing code means checking how well it works, how readable it is and whether it meets the requirements.
- Comparing the code with each requirement shows what it does not yet do.
Have a goYour friend says: 'My scheduler works. It runs without crashing.' Total time is 600 and stream_seconds is 1500, and it accepted one review. Is the code finished?
No. It doesn't yet meet the requirement to add more than one review.
Running without errors isn't the test. Comparing the code with each requirement shows what it does not yet do, such as accepting only one review.
- Refining code can mean simplifying logic, using subroutines or correcting errors.
- A while loop repeating while total_time < stream_seconds lets more than one review be added.
- A for loop with range(len(game_names)) outputs each item in a list.
- Modularity means dividing a program into subroutines, each performing one specific task.
- A function returns a value to the main program. A procedure does not.
Have a goOne line has def show_menu(): and no return. Another has def total_cost(a, b): then return a + b. Which is the function and which is the procedure?
total_cost is the function, show_menu is the procedure.
A function returns a value to the main program and a procedure does not. Both start with def, so the first line alone can't tell you.
- Arguments are passed into parameters, which act as local variables inside the function.
- Comments, layout, meaningful identifiers and naming conventions make code readable and maintainable.
The big picture
Code that runs is not finished. You split the requirements into inputs, processes and outputs, read the code against each one, and refine it where it falls short: simplify the logic, break it into subroutines, correct errors or add a loop. Subroutines (functions and procedures, with parameters and arguments) make development faster and code easier to read, test and maintain, and good practice keeps it readable.
Key points
Worked example
Problem
The stream scheduler checks that a duration is between 20 and 40 minutes in two different places, using the same code copied twice. Refine it with a subroutine.
⚠ Watch out
Thinking subroutines make a program run faster. Modularity makes development faster and code easier to read, test and maintain. And a program that runs without errors can still be unfinished, if it does not meet every requirement.
Memory hook
Read the requirements, tick them off, refine what you can't tick. Then split the code into subroutines to build faster, test easier and write once.
Check yourself
Pick the stream scheduler's requirement 'keep adding game reviews until the stream is full'. Which part of version 1 fails it, and which refinement fixes that?
Flashcards
(14)What do functional requirements define?
What does reviewing code involve?
How do you find what code does not yet do?
Three ways to refine code
Which loop lets the scheduler add more than one review?
Which loop outputs each item in a list?
What is modularity?
Four benefits of modularity
Function or procedure: which returns a value?
How does Python treat functions and procedures?
What are parameters?
How do arguments reach a function?
Four parts of good programming practice
Why does good practice matter?
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 Edexcel GCSE Computer Science topics
- Programming – iteration over data structures
- Programming – selection
- Programming – sequencing
- Programming arithmetic operators
- Programming logical operators
- Programming relational operators
- Single entry/exit code blocks
- String manipulation
- Structural components of programs
- Structured data types
- User input handling
- Validation – length check
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 21 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.