KS3 · Computer Science
Python recap from Year 8
No computer in sight? You're about to become one. By the end you'll read a short Python program and say exactly what it prints before it ever runs.
Computer Science · Algorithms
Trace table — dry run the code
Be the computer. Before you press anything, guess: what will count be when the program ends? Then step through one line at a time and see if you were right.
Ready when you are — step through one line at a time.
Computer Science · Selection
One value, one route
The program checks season from the top. Pick a branch and see what it prints.
Condition checked
4 possible routes.
Four paths: an if, two elif statements and an else. Pick a branch to see which line of the program runs when season holds that value.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Read a short program and say exactly what it prints.
What you need to know
- Python is a text-based programming language, and a list stores related items in order inside square brackets.
- Selection means checking a condition, true or false, then following one path; elif and else add more paths.
- The indented block under an if runs only when its condition, like pet == "cat", is true.
Have a goA program has an if, two elif statements and an else. On one run, how many of those four indented blocks run?
Just one.
Selection follows one path. Even with four blocks written, the other three are skipped.
- A for loop repeats a set number of times, such as once for each item in a list.
- A while loop runs while its condition is true, and stops once the condition is false.
- List indexes start at 0, so days[1] is the second item; days[7] in a seven-item list is an IndexError.
Have a goZed is sure the last item in a 5-item list is at index 5. Zed is very confident. Is Zed right, and which index is the last?
No. The last item is at index 4.
Counting starts at 0, so five items sit at indexes 0, 1, 2, 3 and 4, and index 5 would give an IndexError.
- range(6) counts from 0 up to 5, because the stopping value is never included; range(4) runs 4 times.
Have a goHow many times does for x in range(3): run its body, and what values does x take?
3 times, with x as 0, 1 and 2.
The stopping value is never included, so the count goes up to but not including 3.
- A string is a sequence of characters in speech marks; len() counts them, spaces included, and each has a zero-based index.
- Lists can be changed in place and can grow or shrink; strings can't, so updating one means reassigning the whole value.
- An f-string puts a variable's value into printed text: an f before the opening speech mark, the variable in curly brackets.
The big picture
This lesson recaps the Python you have already met: if, elif and else, for and while loops, range(), lists, strings and f-strings. The skill that ties them together is tracing, which means stepping through a program to work out exactly what it does.
Key points
Worked example
Problem
The user types 2. What does this program print? day = int(input("Which day is it? ")) remaining = 5 - day print(f"{remaining} days until the weekend")
⚠ Watch out
Counting from 1: expecting days[1] to be the first item, or range(6) to include 6. Positions start at 0, and a range stops just before its stopping value.
Memory hook
Start at zero, stop short: the first index is 0, and range() stops just before its stopping value.
Check yourself
Pause and think before you move on. A list has 4 items. Which indexes can you use? And which numbers does range(4) give? What do you notice about the two answers?
Flashcards
(14)What is selection in a program?
What do elif and else add to an if statement?
What do == and != check?
Which loop repeats a set number of times?
When does a while loop run, and when does it stop?
What is the index of the first item in a list?
What happens if you ask for days[7] in a seven-item list?
Why does a program use months[month - 1] when the user types a month number?
What does the stopping value in range() mean?
What are the two ingredients of an f-string?
How can a loop keep adding items to a list?
What do in and not in check?
What does len() count in a string?
Which can be changed in place, a list or a string?
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 KS3 Computer Science topics
How this lesson was checked. This KS3 Computer Sciencelesson 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 7 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.