/en-tutor-prep-s2-ict-programming-basics-python-variables-loops/
/en-tutor-prep-s2-ict-programming-basics-python-variables-loops/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

Junior Secondary ICT (S2) — Programming Basics Lesson-Prep Guide | Variables, Conditions and Loop Tracing

Junior Secondary ICT (S2) — Programming Basics Lesson-Prep Guide | Variables, Conditions and Loop Tracing

  • 2026-11-21

Students can read a program but fall apart when asked to trace the output line by line. This lesson does three things only: variables as named boxes, conditions as forks in a road, loops as repeated copying, with a trace table for every step.

Objectives — By the end students can: (1) explain that a variable is a named storage location and tell integers, strings and floats apart; (2) write a two-branch condition and predict its output; (3) write one for loop and one while loop and count the iterations; (4) trace a short program showing each variable value line by line.

01 Prerequisites (3-minute check)

If any of these fails, fix it before the lesson starts.

Skill Quick check Pass mark
Order of operations What is 2 plus 3 times 4? 14
Averages What is the mean of 12, 15, 9 and 18? 13.5
Comparison If 60 is a pass, does 55 pass? No

02 Lesson flow (60 minutes)

Time Stage Tutor does Student does
0–5 min Prior-knowledge check Ask what a variable is and write the answers up Write a one-sentence definition
5–20 min Act one: variables and types Model assignment and reassignment; show that numbers and strings do not add directly Copy three assignments and write the value after each
20–35 min Act two: conditions Draw the fork, then run a pass and a fail case Write the branch result for two scores
35–45 min Act three: loops Model for and while, filling a trace table Trace a four-iteration loop alone
45–55 min Three independent questions Read only, no hints Solve all three with a trace table each
55–60 min Exit check Read three questions and collect answers Write answers

03 Teaching script (read it out)

Scene 1: A variable is a box with a name on it

Start with assignment: total starts at 0, then a number is added each time. A variable is not an unknown in algebra; it is a named storage location whose contents can change. The integer 5, the float 13.5 and the string Hong Kong are three different types; string plus string joins, while number plus string fails until it is converted. Model a swap: first equals 5 and second equals 3, so set temp to first, set first to second, then set second to temp, giving first as 3 and second as 5. Without the temporary variable both end up holding the same value.

Ask why swapping two values needs a third temporary variable.

Scene 2: A condition is a fork, not arithmetic

The usual misconception is treating a condition as part of the sum. A condition only chooses a path; it never changes the score. Model it: with a score of 55 and the test score not less than 60, the test fails and the program prints fail; with 72 the test passes and it prints pass. Be precise about the boundary: 60 itself passes, so the test is not-less-than rather than greater-than. Indentation is syntax: statements on the same level line up, and an extra or missing level sends the program down the wrong branch or stops it with an error.

Ask which branch a score of 60 takes, and why the test is not greater-than.

Scene 3: A loop is repeated copying, so count the iterations

A for loop takes its count from the range: from 1 up to but not including 5 is five passes, while 1 up to but not including 4 is only four, which is the classic off-by-one error. Model a running total: start at 0 and add 1, 2, 3, 4 and 5 to reach 15. A while loop takes its count from the condition: start at 1 and multiply by 3 until the value exceeds 50, giving 1, 3, 9, 27 and 81, which is four multiplications, with 81 left in the variable. Every question needs a trace table: line number, variable values and whether the loop continues.

Ask for the value left in the variable when the while loop stops.

04 Question types and worked steps

Type Example Steps Answer
Predict the output The total of 1 to 5 Fill a trace table rather than guessing 15
Branch on a condition What do scores 55 and 72 print? Test the condition first, then write the branch Fail and pass
Count iterations Multiplying by 3 until above 50: how many times? List the intermediate values, then count Four times, final value 81
Debug A loop prints four times instead of five Check the upper bound of the range The bound is 4 and should be 5
Sanity check (teach this): Three checks: update the trace table on every reassignment; count iterations rather than reading the final value; never add a number to a string directly. A student who gets 14 for 1 plus 2 plus 3 plus 4 plus 5 has either started at 1 or dropped the last pass.

05 Independent practice (3 questions)

Question Answer What to watch
Write the sum of the even numbers from 2 to 10 30, from 2, 4, 6, 8 and 10 Did they list the five values?
Convert 25 degrees Celsius to Fahrenheit 77 degrees Did they multiply by 9, divide by 5, then add 32?
A loop starts at 1 and multiplies by 3 while the value is less than 50. What is the final value? 81 Did they write 1, 3, 9, 27 and 81?

06 Common mistakes and what to say

Mistake Student writes Say this
Treating a variable as a constant First equals 5, and later changes are ignored A variable changes, so after every line ask what its value is now and write it in the trace table.
Using greater-than instead of not-less-than A score of 60 is marked as a fail 60 passes, so the test must be not-less-than; always run the boundary value once.
Off-by-one in a range A loop should run five times but runs four The upper bound is the number of passes, not the last value; count the intermediate values after writing it.
Inconsistent indentation One block is indented four spaces and another two Statements on the same level line up; wrong indentation sends the program down the wrong branch or raises an error.

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
How does a variable differ from an unknown in algebra? A variable can be reassigned, so its value changes An answer of they are the same means assignment needs reteaching
What does a score of 60 print under a not-less-than 60 test? Pass An answer of fail means the boundary was missed
Starting at 1 and multiplying by 3 while the value stays less than 50: how many multiplications? Four Three means the final pass was dropped

09 Tutor FAQ

Can this be taught before students know any programming language?

Yes. The lesson uses pseudocode and trace tables, with syntax kept minimal; sequence, selection and repetition transfer to any language.

Should functions be introduced straight away?

No. S2 students should first master variables, conditions and loops and trace output themselves; functions come once they can debug alone.

What if a student copies code correctly but cannot explain it?

Ask them to close the screen and re-run the same program aloud with a trace table; if they cannot narrate it, reteach that section.

Find a tutor — freeTutor Registration →

A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →