Year Group: Year 5 · Ages 9–10
Theme: Loops, Variables, Lists & Nested Loops
Missions: 10 Workbook Missions · 16 Game Missions
Language: Python 3
Advanced FOR Loops · Accumulators · WHILE Loops
Welcome to Syntax Station, Captain! Here loops become POWERFUL! range(start, stop, step) gives you total control — even counting backwards!
Write what each range() produces:
| range() call | Numbers produced | Count |
|---|---|---|
range(5) | ||
range(1, 6) | ||
range(0, 10, 2) | ||
range(10, 0, -1) | ||
range(1, 20, 3) |
Write a FOR loop that counts down from 10 to 1, then prints "BLAST OFF! 🚀"
Expected output:
Use a FOR loop to print this triangle pattern:
Your code:
range(1, 6) gives 1, 2, 3, 4, 5. Use "*" * i to print i stars!
An accumulator collects values as the loop runs! Start at 0, add to it each time. It's like a running total!
Trace through this code and fill in the table:
| Iteration | i | total (before) | total (after) |
|---|---|---|---|
| 1 | 1 | 0 | |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 |
Final total:
Write code to calculate the sum of all numbers from 1 to 100:
Answer: The sum of 1 to 100 =
Calculate 5! (5 factorial = 5 × 4 × 3 × 2 × 1). Hint: Start your accumulator at 1, not 0!
5! =
WHILE loops keep going while the condition is True! Perfect when you don't know how many times to repeat!
| Iteration | x (before) | x (after) | Condition (x ≤ 32)? |
|---|---|---|---|
| 1 | 1 | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
Choose the best loop type for each task:
| Task | FOR or WHILE? | Why? |
|---|---|---|
| Print numbers 1 to 10 | ||
| Keep asking for password until correct | ||
| Process each item in a shopping list | ||
| Count down from unknown number to 0 | ||
| Print the 12 times table |
Write a WHILE loop to find the first number greater than 100 that is divisible by both 7 AND 11:
Answer:
break · continue · Lists · Slicing
break exits the loop immediately! continue skips the rest of this iteration and goes to the next! Powerful tools!
What does each program print? Write your answer:
Output:
Output:
| Keyword | What it does | When to use it |
|---|---|---|
break | ||
continue |
Write code to find the first number in range(1, 100) that is divisible by 13. Use break to stop when found:
Answer:
A list stores MANY values! Like a variable that holds a whole collection. Index starts at 0 — the first item is list[0]!
| Expression | Result |
|---|---|
planets[0] | |
planets[2] | |
planets[-1] | |
planets[-2] | |
len(planets) |
Complete the code to use each list method:
Write a FOR loop to print each planet with its index number:
List Slicing · Nested Loops · Loops + Lists
Slicing gets a portion of a list! list[start:stop] — the stop index is NOT included. list[::-1] reverses the whole list!
| Slice | Result |
|---|---|
numbers[2:5] | |
numbers[:3] | |
numbers[7:] | |
numbers[::2] | |
numbers[::-1] | |
numbers[1:8:3] |
Nested loops — a loop inside a loop! Total iterations = outer × inner. Perfect for 2D patterns and grids!
Fill in ALL outputs (9 lines total):
Write nested loops to print a 5×5 grid of stars:
Expected output:
Write nested loops to print the 5×5 multiplication table:
Loops + Lists = POWER! Build lists with loops, process lists with loops. This is where real programming begins!
Complete the code to build a list of squares (1², 2², 3², ... 10²):
Output:
Write code to create a new list containing only scores above 20:
Output:
Write a complete grade system that processes a list of scores:
Output:
Create your own program that uses loops AND lists to solve a real problem. Ideas: shopping list calculator, quiz score tracker, favourite planets list. Save it to your portfolio!
Use ALL your loop and list skills to restore power!
This is your greatest challenge yet — but you have ALL the skills you need! Break it into parts. Solve one part at a time. This is YOUR moment, Captain!
This nested loop has 3 bugs. Find and fix them:
Bug 1:
Bug 2:
Bug 3:
Fixed code:
Write code to track power levels across 5 zones:
Write code to find all zones with power below 50:
Output:
Write nested loops to generate this power grid pattern:
Write a complete program that uses a WHILE loop to keep asking for power readings until the user types "DONE", then calculates the average:
You've mastered loops, variables, lists, and nested loops!
Debugging Dunes awaits, Admiral! 🔬
Accumulator
A variable that collects values as a loop runs (e.g., running total).
break
Exits a loop immediately, even if the condition is still True.
continue
Skips the rest of the current iteration and goes to the next one.
FOR loop
Repeats a block of code a set number of times or for each item in a sequence.
Index
The position of an item in a list. Starts at 0 in Python.
Iteration
One complete run through a loop body.
List
A collection of values stored in a single variable, e.g., [1, 2, 3].
Nested loop
A loop inside another loop. Total iterations = outer × inner.
range()
Generates a sequence of numbers. range(start, stop, step).
Slicing
Getting a portion of a list: list[start:stop:step].
WHILE loop
Repeats while a condition is True. Use when you don't know how many times.
enumerate()
Returns both the index and value when looping through a list.