Sparklabs Learning / Digital Technology
SS 3 First Term
Week 2: Advanced Programming
- School
- Creative Brains Academy
- Subject
- Digital Technology
- Pack
- Full pack
- Prepared
- 7 November 2026
Week index
- 01Senior Review and Computational Problem Solving
- 02Advanced Programming
- 03Functions, Arrays and Data Structures
- 04Object-Oriented Programming
- 05Database Systems
- 06Computer Networks and Internet Technologies
- 07Web Development and Web Design
- 08Software Development Life Cycle
- 09Electronic Commerce
- 10Cyber Security and Emerging Digital Technologies
- 11Revision
- 12Examination
Week 2 / First Term
Advanced Programming
Monday 14 September 2026 to Friday 18 September 2026
Lesson notes
Learning Objectives
- Turn a clear problem statement into a working program.
- Use the control structures of sequence, selection and iteration.
- Write functions and modules with a consistent coding style.
- Build and test a small working program.
From a Clear Problem to a Working Program
Every program is built to solve a problem, so the work of writing code must begin by understanding exactly what the problem is, who faces it and what a good solution must do. A problem is the difficulty to be overcome, such as students being unable to report lost items quickly or a teacher not knowing which pupils have paid fees. A requirement is a precise statement of what the solution must do, for example pupils must be able to submit a lost item report from a phone or the system must show only fully paid students. A solution is the actual product, such as a web app, that meets those requirements. These three ideas are not the same, and jumping to a solution before clearly defining the problem and its requirements is a serious mistake, because the code will solve the wrong thing.
To set requirements properly the engineer analyses the scene and identifies the stakeholders, the people served by the solution, for a school app these might be students, teachers and the office staff. The engineer then records what data goes in, what processing must happen and what results come out. Consider a school assignment-submission reminder app, the inputs are the assignment title, the class and the due date, the processing checks the current date against the due date and flags tasks that are due soon or overdue, and the outputs are reminders and a summary of outstanding work. All of this is written into a requirements document, a short written record that guides both building and testing, with sections such as a title, a problem statement, the users, functional requirements, which state what the system does, non-functional requirements, which state how well it performs, the inputs, processing and outputs, any constraints such as a limited budget, and a security and data-protection plan for keeping user data safe.
Thinking about the problem as a system of connected parts keeps the requirements complete. Systems thinking views the problem as a whole, so a lost-and-found app is not a single form but a chain of reporting, storing, searching, matching and notifying, and each link depends on the others. Computational thinking supplies the tools to manage that complexity, decomposition breaks the whole problem into smaller parts such as reporting, searching, matching and notifying, pattern recognition spots repeated operations that only need to be solved once, abstraction keeps only the details that matter, such as the item type, colour and location, and ignores irrelevant ones, and algorithmic thinking designs a clear sequence of steps to solve each part. These ideas are the bridge between a written requirement and the code that will satisfy it.
An algorithm turns the analysis into plain steps. For example, to compute a class average the steps are to set a total to zero and a count to zero, then for each score add the score to the total and increase the count, then compute the average by dividing the total by the count, and finally display the average. An algorithm is a clear, step-by-step set of instructions, and it can be written as pseudocode or drawn as a flowchart before any programming language is chosen. Writing the algorithm first confirms that the logic is correct and complete before attention turns to the syntax of a particular language, which is why strong programs begin with strong analysis and clear algorithms.
The solution must also be secure from the first design. The three core security principles are confidentiality, keeping data private and visible only to authorised people, integrity, keeping data correct and unchanged by accident or by attackers, and availability, keeping the service up so authorised users can reach it whenever needed. These three are often called the CIA triad. A school app that stores names and grades must protect that data, so passwords are never stored in plain text, logins are required, and personal details are shared only with authorised users. Security is not an afterthought, it is a requirement that constrains the design from the very beginning.
Once the problem, the requirements and the algorithm are clear, the next question is how to write the code in a way that is reliable, readable and easy to maintain. That is the job of structured programming, which organises the logic we just designed into a small set of powerful building blocks. The analysis and the algorithm decide what the program must do; the control structures and functions we study now decide how the code is composed so that it matches that plan exactly and can be tested with confidence.
Control Structures and Structured Programming
Structured programming is a disciplined way of writing programs that relies on three basic control structures, sequence, selection and iteration, together with functions and modules. Its purpose is to produce code that is clear, easy to read, easy to test and easy to maintain. Before structured programming was introduced, programmers used unpredictable jumps (goto statements) that scattered control through a program and made it confusing and costly to fix. Structured programming replaced that chaos with order, and it is the foundation of virtually all modern software engineering.
Sequence means that instructions run one after another from top to bottom. For example, to compute a class average the program reads three scores, adds them and divides by three, each step following the previous one. Selection means the program checks a condition and chooses one of two paths, using if and else. The condition is a Boolean expression that evaluates to true or false. For example, if a student's average is above 75, display Distinction, otherwise display Try harder. Iteration means that a block of instructions repeats, either for a set number of times or while a condition stays true. A for loop is used when the number of repeats is known, such as stepping through a list of thirty students to check each one's fee status. A while loop is used when repetition must continue until a condition changes, such as asking for a password until the correct one is entered. These three structures alone can express any computable task.
Selection in code is written with the if and else keywords. The program evaluates the Boolean expression and runs the matching block of code between curly braces in JavaScript. The double ampersand (&&) combines two conditions so that both must be true. In Python the same idea uses the same keywords, but each header line ends with a colon and the body is indented. Iteration with a for loop underlines how a loop visits each element exactly once, adding it to a running total, after which the final average is computed. Iteration with a while loop shows how a program can keep asking for input until the correct value is given, counting the attempts as it goes.
Functions, Modules and Coding Style
A function is a named block of code that performs a specific task and can be reused. In real software a school app might have functions for calculating averages, checking fee status, sending notifications and formatting reports. Writing logic once as a function and calling it many times reduces repetition and makes a program easier to understand and to fix. A function is defined with the keyword function, a name, parameters in parentheses and a body between curly braces. Parameters are placeholders listed in the definition; arguments are the actual values supplied when the function is called. A function returns a result with the return keyword, or it may simply perform an action and return nothing. In Python the defining keyword is def, followed by the function name, parameters and a colon.
A module is a file containing functions and code that can be imported into other programs. Modules let programmers share and reuse tested code without rewriting it. Python ships with many built-in modules; the math module provides square roots, rounding and constants, while the random module generates random numbers and choices. JavaScript offers a Math object with min, max, round and random methods. Programmers can also build their own modules by saving related functions in one file and importing that file wherever the functions are needed.
Good coding style is as important as correct code, because bad style makes programs hard to understand, debug and maintain. Meaningful names such as studentAverage describe the data, whereas a single letter such as x hides it. Consistent indentation and braces make the structure of blocks obvious. Short, focused functions each carry out one task instead of five. A short comment explains complex logic. Consistent naming such as classLevel and totalScore avoids confusion. These are not decorations; they save real time when debugging and when several people work on the same code.
Debugging is the process of finding and fixing errors. A syntax error stops the program from running because a rule of the language is broken, such as a missing closing brace; the fix is to read the error message, find the line and correct it. A runtime error crashes the program during execution, for example dividing by zero; the fix is to trace the execution step by step and check the values. A logic error allows the program to run but produces the wrong answer, for example using the wrong formula; the fix is to add log or print statements that reveal the intermediate values and compare them with expected results.
Building Small Working Programs
A good small program combines sequence, selection and iteration, organised into functions and written with a clear style. A worked example is a score-analysis program that reads five scores, computes the average and prints the overall grade. Two functions carry the work, computeAverage sums a list with a loop and returns total divided by length, while getGrade uses selection to return Distinction for 75 and above, Credit for 60 and above, and Pass otherwise. A clean main section calls both functions and prints the results. When the program prints a wrong average, the debugging steps are to add a console.log inside computeAverage to inspect the running total, to check that the list really holds the values entered, and to confirm that the length is five before fixing the error and re-running.
The identical logic can be written in Python for a school context, since the ideas transfer directly. JavaScript encloses every block in curly braces and prints with console.log, while Python uses indentation and the print function. A Python function starts with def instead of function; a conditional header ends with a colon; a repeat-over-list uses for x in list. Learners who master the concepts in one language can move to the other with confidence, because structured thinking is the same in both.
This week is the bridge between the analysis of Week 1 and real coding. Decomposition from Week 1 breaks a problem into the exact functions that Week 2 writes. Pattern recognition identifies the repeated operations that become loops. Abstraction hides details that do not matter, and algorithmic thinking designs the step-by-step logic that the code implements. Scenario question, a school teacher wants a program that reads five scores, computes the average and prints whether each student is above or below that average. The inputs are the five scores, the processing is summing, averaging and comparing, and the outputs are the average and the comparison. This is exactly what the score-analysis program delivers.
| Structure | How it works | Example |
|---|---|---|
| Sequence | Instructions run one after another | Read three scores, add them, divide by three |
| Selection (if-else) | Checks a condition and chooses one path | If average is above 75 show Distinction, otherwise show Try harder |
| Iteration (for/while) | Instructions repeat while a condition is true or for a set count | Loop through 30 students and check each fee status |
| Error type | What happens | How to fix |
|---|---|---|
| Syntax error | Program fails to run because of a typing mistake | Read the message, find the line, correct the syntax |
| Runtime error | Program crashes during execution (e.g. dividing by zero) | Trace the execution step by step |
| Logic error | Program runs but gives the wrong answer | Use print statements to check intermediate values |
| Concept | JavaScript | Python |
|---|---|---|
| Function | function name(a, b) { } | def name(a, b) followed by a colon |
| Block of code | Curly braces enclose the body | Indentation defines the body |
| Print output | console.log(value) | print(value) |
| Conditional | if (age >= 18) {. } | if age >= 18 followed by colon |
Practical Work
- Write a program that uses an if statement and a loop.
- Write a function that takes input and returns a result.
- Test the program with normal and unusual input.
- Comment the program so another learner can follow it.
Scenario-Based Questions
- A school portal must read 30 student scores, compute each student's average and print Distinction for an average of 75 or above and Credit for 60 to 74. Write the pseudocode using sequence, selection and iteration, then explain which control structure handles which part of the task.
- A programmer writes a Python function that divides two numbers but forgets to check for zero in the denominator. Describe the type of error this produces, what happens when the program runs, and how to fix it using selection.
- A team is building a JavaScript attendance system. One developer writes all the logic inside a single main() function with no other functions. Explain why this violates structured programming principles and describe two benefits of splitting the logic into separate functions.
- During testing, a student attendance app always counts every student present even when some are absent. The program runs without errors. Identify the error type and describe a debugging strategy using print statements to find the wrong condition.
- A programmer is comparing Python and JavaScript for a school project. Using the differences in function syntax, block definition and output commands shown in the notes, rewrite the following Python code in equivalent JavaScript: def greet(name): print('Hello ' + name).
- A banking application calculates interest using sequence: it reads the balance, multiplies by the rate and prints the result. A junior programmer adds the interest back to the balance before recalculating, producing wrong totals. Explain why the order of sequence matters and show the correct sequence.
- A shop owner wants a stock program. A function checkStock(item, quantity) must return True if quantity is available and False otherwise. Write this function in Python, explain the role of the parameter and the return value, and describe how the main program would use it inside a loop to check multiple items.
Teacher plan
LEARNING OBJECTIVES: BY THE END OF THE LESSON STUDENTS SHOULD BE ABLE TO:
| Cognitive | i. Turn a clear problem statement into a working program. ii. Use the control structures of sequence, selection and iteration. iii. Write functions and modules with a consistent coding style. iv. Build and test a small working program. |
| Affective | i. Appreciate the value of Advanced Programming in school, at home and in the community. ii. Show willingness to use digital tools carefully, safely and responsibly. |
| Psychomotor | i. Write a program that uses an if statement and a loop. ii. Write a function that takes input and returns a result. iii. Test the program with normal and unusual input. iv. Comment the program so another learner can follow it. |
Rationale: Every program is built to solve a problem, so the work of writing code must begin by understanding exactly what the problem is, who faces it and what a good solution must do. Understanding from a Clear Problem to a Working Program, control Structures and Structured Programming, functions, Modules and Coding Style, building Small Working Programs helps learners use digital technology confidently, safely and responsibly.
Pre-requisite Knowledge: In Week 1, learners studied Senior-Level Review and Computational Problem Solving, including senior-Level Review, computational Thinking and the Four Pillars, problem Analysis and Drafting a Requirements Document. The knowledge from that week is used again in this lesson.
Learning Material/Teaching Aid: Whiteboard, markers, computer or laptop where available, printed notes and charts on Advanced Programming, practical task sheets, learners' notebooks and pens.
Reference Materials: Digital Technology for Senior Secondary Schools (SS 3); NERDC Digital Technology Curriculum; Digital Technology SS 3 First Term Notes (Week 2); First Term examination and Continuous Assessment question papers.
LESSON DEVELOPMENT
| Stage/Step (Time) | Teacher's Activities | Student's Activities | Learning Points |
|---|---|---|---|
| Introduction 5 MINUTES | Welcomes learners, revises Week 1 (Senior-Level Review and Computational Problem Solving) with two quick oral questions, and asks what they already know about Advanced Programming. Elicits responses and writes the topic on the board. | Recall the previous lesson and share what they already know about Advanced Programming. | Connecting prior knowledge to Advanced Programming. |
| Step 1 6 MINUTES | Covers From a Clear Problem to a Working Program: Every program is built to solve a problem, so the work of writing code must begin by understanding exactly what the problem is, who faces it and what a good solution must do. | Listen, take notes and answer oral questions on "From a Clear Problem to a Working Program". | Understanding: From a Clear Problem to a Working Program. |
| Step 2 6 MINUTES | Covers Control Structures and Structured Programming: Structured programming is a disciplined way of writing programs that relies on three basic control structures, sequence, selection and iteration, together with functions and modules. Its purpose is to produce code that is clear, easy to read, easy to test and easy to maintain. | Copy the key points, give examples from school and everyday life, and ask questions on "Control Structures and Structured Programming". | Understanding: Control Structures and Structured Programming. |
| Step 3 6 MINUTES | Covers Functions, Modules and Coding Style: A function is a named block of code that performs a specific task and can be reused. In real software a school app might have functions for calculating averages, checking fee status, sending notifications and formatting reports. | Discuss in pairs, then report one point on "Functions, Modules and Coding Style" to the class. | Understanding: Functions, Modules and Coding Style. |
| Step 4 6 MINUTES | Covers Building Small Working Programs: A good small program combines sequence, selection and iteration, organised into functions and written with a clear style. A worked example is a score-analysis program that reads five scores, computes the average and prints the overall grade. | Respond to questions, complete the examples on the board and note down "Building Small Working Programs". | Understanding: Building Small Working Programs. |
| Practical Work 6 MINUTES | Guides learners through the practical work: (i) Write a program that uses an if statement and a loop. (ii) Write a function that takes input and returns a result. (iii) Test the program with normal and unusual input. Moves round the class to check progress and correct unsafe or careless use. | Carry out the practical tasks individually or in pairs and record what they did in their notebooks. | Applying the lesson through hands-on practice. |
| Evaluation 3 MINUTES | Asks learners to: i. Turn a clear problem statement into a working program. ii. Use the control structures of sequence, selection and iteration. iii. Write functions and modules with a consistent coding style. iv. Build and test a small working program. | Respond verbally and in writing to the evaluation questions. | Assessment and consolidation of the lesson content. |
| Conclusion 2 MINUTES | Recaps the main points: from a Clear Problem to a Working Program, control Structures and Structured Programming, functions, Modules and Coding Style, building Small Working Programs. Links them to the assignment and previews Week 3: Functions, Arrays and Data Structures. | Listen, ask questions and copy the assignment. | Reinforcement of key concepts and a preview of the next lesson. |
Assignment: i. Before structured programming, a program was full of unpredictable jumps that made it costly to fix. Explain what structured programming is, name its three control structures, and give a situation in which each is used. ii. A school portal must read 30 student scores, compute each student's average and print Distinction for an average of 75 or above and Credit for 60 to 74. Write the pseudocode using sequence, selection and iteration, then explain which control structure handles which part of the task.