/en-tutor-prep-s3-ict-python-basics/
/en-tutor-prep-s3-ict-python-basics/
英文版
3
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

S3 ICT | Python Programming Basics — Lesson-Prep Guide for Tutors | Variables, input Conversion, range and Dry Runs

S3 ICT | Python Programming Basics — Lesson-Prep Guide for Tutors | Variables, input Conversion, range and Dry Runs

  • 2026-11-11

Students can print a line but cannot say why total becomes 55. The problem is not syntax; they have no picture of a value changing each pass. One dry-run table turns the loop from a spell into a traceable procedure.

Objectives — Students can: (1) explain that a variable is a name attached to a value and that a = a + 1 computes the right side first; (2) use range(1, 11) to total 1 to 10 and get 55, explaining why it is ten numbers and not eleven; (3) fill a dry-run table for i and total to locate off-by-one and missing int() errors.

01 Prerequisites (3-minute check)

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

Skill Quick check Pass mark
Integers and averages What is 1 plus 2 up to 10, and the average? 55 and 5.5
Keywords What do for and while each imply? for walks through values; while repeats while a condition holds
Assignment direction Which is legal, a = 3 or 3 = a? The first; the equals sign puts the right value into the left name

02 Lesson flow (45 minutes)

Time Stage Tutor does Student does
0-5 min Estimate first Ask what total is after ten passes of total = total + i; write the guess down. Most guess 10 or 100, revealing no value trace
5-13 min A variable is a label Show a = 1 then a = a + 1, stressing the right side is computed first. Write the value of a twice
13-26 min The range boundary Write range(1, 11) and range(10), list both, note the right boundary is excluded. List both sets of numbers
26-34 min Dry-run table Draw columns for i and total and fill ten rows to reach 55. Fill three rows themselves
34-41 min Two error types Show the effect of a missing int() and of range(1, 10), then fix each. Explain the difference
41-45 min Exit check Collect three answers and mark them on the spot. Hand in three answers

03 Teaching script (read it out)

Scene 1: Act 1: the equals sign attaches, it does not compare

“a = 1, then a = a + 1, and a becomes 2. Why? The right side is computed first: 1 plus 1 is 2, then 2 is attached to the name a. So a = a + 1 is not a contradiction, it means ‘use the old value to compute a new one’. When a student asks whether that line is a mistake, they have no picture yet. total = 0; total = total + i works the same way: each pass takes the previous total, adds this pass’s i, and stores it back. A program is not computed all at once; it is changed pass by pass, which is exactly why you copy values down as you trace.”

Compute the right side, then attach it to the left; every pass changes it.

Scene 2: Act 2: the right boundary of range is excluded

“range(1, 11) produces 1 to 10, ten numbers. range(10) produces 0 to 9, also ten. Both run ten times but start differently. Write range(1, 10) and you get nine numbers, so the total is 45 instead of 55, because 10 is missing. That is an off-by-one error. Check it two ways: print list(range(1, 11)) and count, or use first plus last times count divided by two, which gives (1 + 10) times 10 divided by 2 equals 55. If the program disagrees with the formula, the boundary or the count is wrong.”

range(1, 11) is 1 to 10; the right boundary is excluded, which causes off-by-one.

Scene 3: Act 3: the dry-run table is the fastest debugger

“When a program is wrong, it is usually not the computer: the version in your head differs from the one the computer ran. A dry-run table has few columns: pass, i, total, output. Pass one: i is 1, total goes from 0 to 1. Pass two: i is 2, total becomes 3. Pass three: total becomes 6. Fill to pass ten and total is 55. By pass three you can already see the rule: total adds i each time. If the program prints 45, the table shows one pass missing, so go and check the range. Debugging is not random editing; it is deciding what each pass must be.”

Copy i and total pass by pass; the wrong pass is visible at once.

04 Question types and worked steps

Type Example Steps Answer
Predict the output total = 0; for i in range(1, 6): total = total + i; print(total) (1) List what range produces (2) Add pass by pass (3) Verify with the formula 15 (1+2+3+4+5); the formula (1+5) times 5 divided by 2 also gives 15
Find the error n = input(“Number: “); print(n + 1) raises an error. Why? (1) Check the type returned by input (2) Name it as a string (3) Wrap with int() (4) Mention validation input returns a string and a string cannot be added to an integer; use int(input(…))
Dry-run table x = 3; while x > 0: print(x); x = x – 1 (1) Write the condition (2) List x each pass (3) Say when it stops 3, 2, 1; when x reaches 0 the condition 0 > 0 is false and the loop stops
Write a program Read five scores and print the average. (1) Loop five times (2) Convert each with int() and accumulate (3) Divide by five (4) Round the result total = 0; for i in range(5): total = total + int(input()); print(round(total / 5, 2))
Sanity check (teach this): Sanity check: 1 to 10 totals 55, not 45 (45 is 1 to 9); 1 to 100 is 5050; the average of 55 over ten values is 5.5, not 55; range(1, 11) holds ten numbers, not eleven; 7 // 2 is 3 and 7 % 2 is 1. Any total larger than the number of passes times the maximum value means extra passes ran.

05 Independent practice (3 questions)

Question Answer What to watch
What is total after total = 0; for i in range(1, 101): total += i? 5050 Checked with (1+100) times 100 divided by 2
Why does print(“5” + 1) fail while print(int(“5”) + 1) works? String plus integer is a type mismatch; the second converts first Names the type rather than just saying “add int”
Write an infinite while loop, then fix it. Condition always true, e.g. x = x + 1 with condition x > 0; fix by decrementing States that the condition must eventually become false

06 Common mistakes and what to say

Mistake Student writes Say this
Forgetting int() “n = input(); print(n + 1)” “input gives you text, not a number. Text plus one is an error. Convert with int() first and the program runs.”
range off-by-one “range(1, 10) means 1 to 10.” “The right boundary is excluded. range(1, 10) gives nine numbers and totals 45. For ten numbers write range(1, 11).”
Inconsistent indentation “Some lines in the loop body use two spaces, some four.” “Python uses indentation to decide what is inside the loop. Align the same level or the computer reads it as two separate things.”
Using = for comparison “if x = 5:” “A single equals assigns; comparison needs two. That line raises a syntax error before it runs.”

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
How many numbers does range(1, 11) produce? Ten, from 1 to 10 Wrong: reteach Act 2
What is 1 plus 2 up to 10? 55 Wrong: reteach Act 3
What type does input() return? A string (str); convert with int() or float() before arithmetic Wrong: reteach Act 1

09 Tutor FAQ

Teach for or while first?

for first, because the count is explicit and easy to trace; bring in while when the number of passes is unknown.

Do students need to memorise syntax?

Only print, input, int, range, if and for; the real skill is tracing values and debugging.

Why insist on a dry-run table?

Because working code with the wrong answer is common, and only a value trace shows whether the fault is a boundary, a type or indentation.

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 →