/en-tutor-prep-s5-ict-programming-python-basics/
/en-tutor-prep-s5-ict-programming-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

DSE ICT | Python Basics: a ten-section tutor guide (variables, loops, functions, debugging)

DSE ICT | Python Basics: a ten-section tutor guide (variables, loops, functions, debugging)

  • 2026-11-05

Students follow an example but freeze at a blank file because they treat a program as syntax to memorise rather than a sequence of instructions. This lesson does one thing: take the sum from 1 to 10 and add variables, a loop and a function in turn, so the same task grows from three lines to ten and every change can be explained.

Objectives — Students can: (1) use a variable to hold and update a running total, stating its value after each line; (2) use a for loop with range for repeated arithmetic, setting the start and stop correctly; (3) wrap the logic in a function, pass an argument and return a result, then verify it with a test value.

01 Prerequisites (3-minute check)

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

Skill Quick check Pass mark
Input and output What do print and input do? Print shows text, input collects a string
Data types Why convert what input returns? Input gives a string, so int is needed
Indentation How does Python group instructions? By indentation, usually four spaces

02 Lesson flow (45 minutes)

Time Stage Tutor does Student does
0-6 min Read a broken program Project a five-line sum that fails and ask students to find the faults Students name at least one fault
6-14 min A variable is a box Trace total equals total plus i turn by turn on the board Students hand-write three rounds
14-24 min for and range Explain why range of 1 to 11 stops at 10: start included, stop excluded Students rewrite for 1 to 100 and check 5050
24-32 min Wrap it in a function Define total_to with a parameter and return; contrast return with print Students wrap the sum and call it once
32-40 min Test and debug Test with 1, 10 and 100, one of which fails deliberately Students find and fix the failure
40-45 min Exit check Collect three answers, read only Work alone

03 Teaching script (read it out)

Scene 1: Open with a broken program

Do not start with syntax. Project a five-line sum holding three faults: total never initialised, range written as 1 to 10, and one line indented to two spaces. Pairs hunt for faults, then their findings go back on the board.
The purpose is to show that programming is mostly fault finding, not writing from scratch. Once that is established, a blank file stops being frightening.

Students do: find the three faults and say what each one breaks.

Scene 2: Variables: boxes updated in turn

Draw one box labelled total and update it round by round: after round one it holds 1, after round two it holds 3, after round three it holds 6. Ask students for round ten, which is 55.
The common misreading is that total equals total plus i is an equation. Say clearly that the right side is evaluated first and the result is put back into the box. That wording lands better than the phrase assignment operator.

Students do: fill a ten-row table of i and total.

Scene 3: for and range: the stop is excluded

The range from 1 to 11 produces ten numbers, and writing 1 to 10 instead loses the 10, which is where marks disappear. One line printing the list makes it visible in a second, better than any explanation.
Then change the task from 1 to 10 into 1 to 100, whose answer is 5050, and let students press it themselves. Same task, different number: students see that the procedure matters, not the arithmetic.

Students do: rewrite for 1 to 100 and explain why 101 appears.

Scene 4: Wrap it in a function

Define total_to taking n, loop over 1 to n plus 1, and return the total. Two points must be explicit: n plus 1 exists because the stop is excluded, and return hands a value back rather than printing it.
Show print of total_to ten against assigning it to x: only the second can be used again. Once that is clear, students stop writing functions that are one long print statement.

Students do: rewrite the function for any n and verify n equals 10 gives 55.

Scene 5: Debug by breaking it on purpose

Give three test values, 1, 10 and 100, expecting 1, 55 and 5050. Then change the loop to stop at n, rerun with 10, and the result is 45, exactly 10 short. Ask students to find the gap and explain it.
That deliberate failure shows why testing matters: a program tested only with 1 passes even when broken. This is usually the quietest, most focused ten minutes of the lesson.

Students do: find the gap between 45 and 55 and write its cause in one line.

04 Question types and worked steps

Type Example Steps Answer
Fill the blank One line missing from a program Trace the data flow before the syntax Indentation and names both correct
Trace Given a program and input, state the output Write every variable value, one row per line Include lines where nothing changes
Debug One logical fault in the code Test a small input first, then locate it Name the line and the reason
Write Produce a function from a description Define input, processing and output Has a return and a test value
Sanity check (teach this): Sanity checks: (1) the sums 55 and 5050 are landmarks worth memorising; (2) a result of 45 means one value was skipped, usually a wrong stop in range; (3) endless output means the loop variable is never updated; (4) a TypeError usually means input was not converted with int; (5) no function is finished until it has passed two different inputs.

05 Independent practice (3 questions)

Question Answer What to watch
Trace Write the total after each round for 1 to 10 Check rounds one, two and ten
Debug Fix the 1 to 10 range and explain Check the explanation mentions the excluded stop
Write Write total_to for any n and test 100 Check it returns 5050

06 Common mistakes and what to say

Mistake Student writes Say this
Total never initialised Writing total equals total plus i straight away “Total does not exist in round one. Give it a zero first.”
Wrong stop in range Writing 1 to 10 and losing the final value “Your answer is 10 short. The stop is excluded, so write 11.”
Print instead of return A function that only prints, so nothing comes back “Print shows, return hands over. Which one does the caller need?”
Inconsistent indentation One line at four spaces and the next at two “These look alike but Python reads them as different blocks. Line them up.”

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
Updating a variable Right side first, then the box Cannot state it, redo act two
range boundaries Start included, stop excluded Boundary wrong, redo act three
return versus print Return hands back, print shows Confused, redo act four

09 Tutor FAQ

Must students memorise syntax?

No. Recognise four shapes: assignment, for, def and return.

Which Python version?

Python 3 style; the exam does not demand a version, but input must be converted.

What if they cannot start?

Write three steps in plain words first: input, processing, output, then translate line by line.

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 →