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.

1pets = ["cat", "dog", "cat", "fish", "cat"]
2count = 0
3for pet in pets:
4 if pet == "cat":
5 count = count + 1
6print(count)
pet
count
Output
Press Start to run the first line.
·

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.

On season = ?. 4 branches to choose from.

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.

Computer Science · Lists

Where does a list start counting?

days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

Which of these is closest to what you think right now?
How sure are you?

Computer Science · range()

Where does range(1, 6) start and stop?

range(1, 6) has a start of 1 and a stopping value of 6. Set both ends of the numbers it gives, and decide whether each end is included. (The loop steps along in whole numbers: 1, 2, 3 and so on.)

Computer Science · while loops

Build a while loop

Build a program that keeps asking for a snack and adds it to the list, while the list holds fewer than 3 snacks.

  1. snacks = ["apple"]The list starts with one snack in it, so len(snacks) is 1.
  2. missing step
Which line is step 2?

Computer Science · Lists and strings

List, string, or both?

For each feature, decide: does it belong to lists only, strings only, or both? Tick every set that fits.

  • A Lists
  • B Strings
  1. Indexes start at 0
  2. len() gives how many items or characters there are
  3. The in operator can check whether something is inside
  4. Stores things in a sequence
  5. Written inside square brackets
  6. Items are separated by commas
  7. Written inside speech marks
  8. Can grow or shrink as items are added or removed
  9. Contents can be changed in place
  10. Updating it means reassigning the whole value
  11. Digits inside it are handled as text, not numbers

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

1Trace a program line by line: write down what each variable holds and whether each condition is true or false.
2Lists, strings and range() all count from 0, and range() stops just before its stopping value.
3A for loop runs a set number of times; a while loop runs while its condition is true.
4Lists can be changed in place, but a string has to be reassigned as a whole.
5An f before the opening speech mark lets {variable} show its value inside printed text.

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?
The program checks a condition, which is true or false, and then selects which path of action to follow.
What do elif and else add to an if statement?
Further paths. Four seasons need an if, two elif statements and an else.
What do == and != check?
== checks that two values are equal; != checks that they are not equal. Each comparison is true or false.
Which loop repeats a set number of times?
A for loop. This is count-controlled iteration.
When does a while loop run, and when does it stop?
It runs while its condition is true and stops once the condition is false. This is condition-controlled iteration.
What is the index of the first item in a list?
0. List indexing is zero-based.
What happens if you ask for days[7] in a seven-item list?
An IndexError, because there is no item at that index.
Why does a program use months[month - 1] when the user types a month number?
The user counts months from 1, but list indexes start at 0.
What does the stopping value in range() mean?
The count goes up to but does not include it. range(6) gives 0 to 5, because it starts at 0 by default.
What are the two ingredients of an f-string?
An f before the opening speech mark, and the variable placed inside curly brackets.
How can a loop keep adding items to a list?
A while loop can ask for an item and append it while len(list) is below a limit.
What do in and not in check?
in checks whether one string is contained in another as adjacent characters. not in checks that a value does not appear in a string or list.
What does len() count in a string?
The number of characters, spaces included.
Which can be changed in place, a list or a string?
A list is mutable. A string is immutable, so updating it means reassigning the whole value.

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 posted

More KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

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.

Helpful guides for parents and students