Hello, superstar coder! In Module 2, you learned about variables, data types, and conditions. You can now store information and make decisions in your programs. But what if you need to repeat something many times? Or what if you have a whole list of items to work with?
Welcome to Module 3 – where we learn about loops (doing things again and again) and lists (holding many items together). We will also take our first steps into real code using a language called Python. Don’t worry – we will start slowly and explain everything.
By the end of this module, you will be able to write simple Python programs that use variables, conditions, loops, and lists. You will feel like a real programmer!
After this module, you will be able to:
while loop and a for loop (in pseudo‑code and Python).Chidi had to water 10 plants every morning. He walked to each plant, poured water, and moved to the next. That’s a lot of walking! He thought, “I wish I could tell someone to do this for me.”
His older brother, who was a software engineer, said: “Chidi, you can tell a computer to do it. Just say: repeat 10 times: water a plant.”
Chidi also had a list of plants: “Rose, Mango, Banana, Orange…” He kept the list on his phone. He could go through the list one by one.
That day, Chidi learned about loops (repeating) and lists (keeping items together). He realised that computers are great at doing boring, repetitive tasks quickly.
Now, let’s learn how to make computers do the same!
Definition: A loop is a programming structure that repeats a block of code multiple times.
Why is it important? Without loops, you would have to write the same code over and over – very boring and error‑prone!
Simple explanation: Think of a loop as telling your computer: “Do this thing, and keep doing it until I tell you to stop.”
Real‑life example: A washing machine runs a cycle – it repeats washing, rinsing, and spinning.
School example: Your teacher takes attendance every morning – that’s a daily loop.
Home example: You brush your teeth twice a day – that’s a loop.
Nigerian example: A traffic light cycles through red, yellow, green – that’s a loop.
Illustration:
+------------------+
| Start |
+--------+---------+
|
+--------v---------+
| Do something | <--+
+--------+---------+ |
| |
+--------v---------+ |
| Still need to | |
| repeat? | ---+ (if yes, go back)
+--------+---------+
|
+--------v---------+
| End |
+------------------+
Mini summary: A loop repeats a block of code as many times as needed.
Definition: A while loop repeats as long as a condition is true.
Why is it important? It allows you to repeat actions based on a condition – very flexible.
Simple explanation: “While my piggy bank is not full, I will add more money.”
Real‑life example: While the water is boiling, keep stirring.
School example: While there are still questions on the test, keep answering.
Home example: While the popcorn is popping, keep the lid on.
Nigerian example: While the bus is not full, the driver keeps waiting for more passengers.
Illustration:
count = 0
while count < 5:
print("Hello")
count = count + 1
// This prints "Hello" 5 times.
Mini summary: The while loop runs as long as the condition is true.
Definition: A for loop repeats a block of code for each item in a collection (like a list or a range of numbers).
Why is it important? It’s perfect when you know exactly how many times you want to repeat, or when you want to go through a list.
Simple explanation: “For each fruit in my basket, I will eat it.”
Real‑life example: A teacher calls each student’s name from the register – one by one.
School example: You check each question on a test paper.
Home example: You go through each item on your shopping list.
Nigerian example: A cashier scans each item in a customer’s basket.
Illustration:
for i in range(1, 6):
print(i)
// Prints: 1, 2, 3, 4, 5
Mini summary: The for loop runs for each item in a collection.
Definition: A list is a collection of items stored together in one variable. It can hold numbers, text, or even other lists!
Why is it important? Lists let you group related items so you can work with them easily.
Simple explanation: A list is like a bag of marbles – you can put many marbles in one bag, and you can take them out one by one.
Real‑life example: A shopping list – you have many items in one list.
School example: A class list of students.
Home example: A list of chores for the week.
Nigerian example: A list of markets in Lagos: “Balogun, Mile 12, Tejuosho”.
Illustration:
fruits = ["apple", "orange", "banana"] // fruits[0] is "apple" // fruits[1] is "orange" // fruits[2] is "banana"
Mini summary: A list stores multiple items in a single variable.
Definition: You can get an item from a list using its index (position). Indexing usually starts at 0.
Why is it important? You need to be able to read and change individual items in a list.
Simple explanation: If you have a list of 3 fruits, the first fruit is at position 0, the second at position 1, the third at position 2.
Real‑life example: In a queue, the first person is number 1 (but in programming we start at 0!).
School example: Your class list – the first student is at index 0.
Home example: The items on your shelf – first item at index 0.
Nigerian example: The list of players on a football team – the first player is index 0.
Illustration:
fruits = ["apple", "orange", "banana"] print(fruits[0]) // apple print(fruits[1]) // orange print(fruits[2]) // banana
Mini summary: Use square brackets and the index number to access list items.
Definition: You can change an item in a list by assigning a new value to its index.
Why is it important? Lists are dynamic – their contents can change while the program runs.
Simple explanation: If you have a list of the top 3 players, you can change who is number 1.
Real‑life example: You update your shopping list – crossing off items and adding new ones.
School example: You update the class attendance – marking students present or absent.
Home example: You change the chore list for the week.
Nigerian example: You update the list of items in your market stall.
Illustration:
fruits = ["apple", "orange", "banana"] fruits[1] = "grape" // now fruits = ["apple", "grape", "banana"]
Mini summary: You can change list items by assigning a new value to a specific index.
Definition: You can add new items to a list (e.g., with append()) or remove items.
Why is it important? Real‑world lists change – you need to be able to add and remove.
Simple explanation: Like adding a new fruit to your fruit bowl or taking one out.
Real‑life example: You add a new friend to your contact list.
School example: You add a new student to the class list.
Home example: You add an item to your shopping list.
Nigerian example: You add a new product to your online store’s catalogue.
Illustration:
fruits = ["apple", "orange"]
fruits.append("banana") // adds "banana" at the end
// fruits is now ["apple", "orange", "banana"]
Mini summary: Lists can grow and shrink – you can add and remove items.
Definition: You can use a for loop to go through every item in a list.
Why is it important? This is one of the most common tasks in programming – processing all items in a collection.
Simple explanation: “For each fruit in my fruit list, I will print its name.”
Real‑life example: A waiter reads each order from a list.
School example: The teacher calls each name from the class list.
Home example: You go through your shopping list and tick each item.
Nigerian example: A bus conductor reads each passenger’s destination from a list.
Illustration:
fruits = ["apple", "orange", "banana"]
for fruit in fruits:
print(fruit)
// Prints: apple, orange, banana (each on a new line)
Mini summary: Loops let you process every item in a list efficiently.
Definition: Python is a real programming language that is easy to read and write. We will now start writing actual Python code.
Why is it important? Python is used by millions of developers – it’s a great first language.
Simple explanation: Pseudo‑code is like a rough draft; Python is the final, running version.
Real‑life example: A chef writes a recipe (pseudo‑code) and then cooks the meal (Python).
School example: You plan an essay outline (pseudo‑code) and then write the full essay (Python).
Home example: You plan a party (pseudo‑code) and then execute the plan (Python).
Nigerian example: An architect designs a building (pseudo‑code) and then workers build it (Python).
Illustration:
// Pseudo-code:
score = 70
if score >= 70:
print("Pass")
else:
print("Fail")
// Python code (exactly the same!):
score = 70
if score >= 70:
print("Pass")
else:
print("Fail")
Mini summary: Python code looks very similar to pseudo‑code – it’s easy to learn!
Definition: A Python program is a file containing Python code. You can run it to see the output.
Why is it important? This is where you bring all your learning to life!
Simple explanation: You type code in a file, save it, and run it – the computer follows your instructions.
Real‑life example: You write a recipe, follow it, and enjoy the meal.
School example: You write a story, read it aloud, and others hear it.
Home example: You write a shopping list, go to the shop, and buy the items.
Nigerian example: You write a list of errands, go out, and complete them.
Illustration:
# This is a Python program
name = "Chidi"
age = 10
print("Hello, my name is", name)
print("I am", age, "years old.")
Mini summary: A Python program is a file with code that you can run.
Definition: Python uses if, elif, and else to make decisions, just like pseudo‑code.
Why is it important? This is how you add logic to your programs.
Simple explanation: “If it rains, take an umbrella; else, take sunglasses.”
Real‑life example: If your phone battery is low, charge it; else, keep using it.
School example: If you score above 80, you get an A; else, you get a B.
Home example: If the door is open, go inside; else, use the key.
Nigerian example: If the bus is full, wait for the next one; else, board.
Illustration:
score = 85
if score >= 70:
print("Pass")
elif score >= 50:
print("Remedial")
else:
print("Fail")
Mini summary: Python conditions work just like the ones you learned in pseudo‑code.
Definition: The while loop in Python repeats as long as a condition is true.
Why is it important? It gives you flexible repetition.
Simple explanation: “While I have money, I will keep buying.”
Real‑life example: While the traffic light is red, you wait.
School example: While the teacher is talking, you listen.
Home example: While the popcorn is popping, you wait.
Nigerian example: While the okada (motorcycle) is moving, you hold tight.
Illustration:
count = 0
while count < 5:
print("Looping!")
count = count + 1
Mini summary: Python's while loop works the same as in pseudo‑code.
Definition: The for loop in Python iterates over a sequence (like a list or range).
Why is it important? It’s the most common way to iterate in Python.
Simple explanation: “For each player on the team, print their name.”
Real‑life example: For each item in your shopping list, buy it.
School example: For each student in the class, mark attendance.
Home example: For each chore on the list, do it.
Nigerian example: For each market in the list, visit it.
Illustration:
fruits = ["apple", "orange", "banana"]
for fruit in fruits:
print("I like", fruit)
Mini summary: Python's for loop makes it easy to go through lists.
Definition: You can use loops to process every item in a list – this is very powerful.
Why is it important? It allows you to perform operations on all items in a collection.
Simple explanation: You have a list of numbers, and you want to add 1 to each number.
Real‑life example: A teacher adds 10 points to each student’s score.
School example: You check each answer in a test.
Home example: You update the quantity of each item on your shopping list.
Nigerian example: A trader updates the price of each item in her store.
Illustration:
numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
numbers[i] = numbers[i] + 1
// numbers is now [2, 3, 4, 5, 6]
Mini summary: Loops and lists work together to process collections of data.
Definition: A real Python program combines variables, conditions, loops, and lists to solve a problem.
Why is it important? This is what software engineers do every day – writing programs that solve problems.
Simple explanation: You write a program that helps you organise your tasks.
Real‑life example: A to‑do list app that lets you add, remove, and view tasks.
School example: A program that calculates your average grade.
Home example: A program that helps you plan your weekly meals.
Nigerian example: A program that calculates the total cost of items in a market basket.
Illustration:
# Program to calculate the average of numbers in a list
numbers = [10, 20, 30, 40, 50]
total = 0
for num in numbers:
total = total + num
average = total / len(numbers)
print("Average is", average)
Mini summary: Real programs combine all the elements you have learned to solve useful problems.
| Word | Simple Definition |
|---|---|
| Loop | Repeating a block of code multiple times. |
| While Loop | A loop that repeats while a condition is true. |
| For Loop | A loop that repeats for each item in a collection. |
| List | A collection of items stored together. |
| Index | The position of an item in a list (starting at 0). |
| Append | Adding an item to the end of a list. |
| Python | A real programming language that is easy to learn. |
| A Python function that displays output. | |
| Range | A function that generates a sequence of numbers. |
| Iterate | To go through each item in a collection. |
while.count < 5).:.count = count + 1) to avoid infinite loops.for.fruit).in and the list name (e.g., fruits).:.This module is a transition from pseudo‑code to real Python. Focus on the similarities – Python code looks almost exactly like pseudo‑code. Emphasise indentation and the importance of avoiding infinite loops. Use interactive exercises where students can run Python code (even mentally). Celebrate each small success.
Encourage your child to write small Python programs on paper. Help them set up a Python environment on a computer if possible. Ask them to explain what a loop is and how it works. Relate loops to daily routines – “What do you repeat every morning?”
for loop in Python can also loop through strings, not just lists?while loop.= instead of == in conditions – assignment vs comparison.
Start
|
v
Condition true? → No → End
|
Yes
|
v
Execute block
|
v
(go back to condition)
| Feature | While Loop | For Loop |
|---|---|---|
| Condition | Checked each time | Built-in for each item |
| Best for | When you don't know how many times | When you know the count or have a list |
| Risk | Infinite loop if condition never false | Less risk, because it stops after the list ends |
| Operation | Example | Result |
|---|---|---|
| Access | fruits[0] | First fruit |
| Change | fruits[1] = "grape" | Second fruit becomes "grape" |
| Add (append) | fruits.append("mango") | Adds "mango" at the end |
| Length | len(fruits) | Number of items in the list |
You have completed Module 3 – a huge milestone! You learned about loops (while and for) that let you repeat code. You discovered lists – powerful containers that hold multiple items. Most importantly, you started writing real Python code that runs on a computer. You now understand the core elements of programming: variables, data types, conditions, loops, and lists.
You can now write simple programs that can solve real problems. Remember, programming is a skill – the more you practice, the better you become. In Module 4, we will go deeper into functions and more advanced Python features.
You are now an official Python beginner – well done!
while repeats based on a condition, for repeats for each item in a collection.append() method.range() in Python? It generates a sequence of numbers for loops.while loop do?for loop do?while and for?len() do?for loop can only be used with lists. (False – it can also be used with strings, ranges, etc.)append() removes an item from a list. (False – it adds.)while loop always runs at least once. (False – it checks the condition first.)forwhiledorepeatadd()append()insert()push()print() do in Python?for loop in Python?for i in range(5):for i to 5:for i=1 to 5:for i in 5:len() do?items?items[1]items[2]items[0]items.get(1)for loop?range(1, 6) function generate?| Term | Definition |
|---|---|
| 1. Loop | A. A collection of items |
| 2. List | B. Repeating code |
| 3. Index | C. Position of an item in a list |
| 4. Append | D. Add an item to a list |
| 5. Python | E. A real programming language |
Answers: 1‑B, 2‑A, 3‑C, 4‑D, 5‑E
while loop and a for loop.names?range() in a for loop?Scenario 1: You are writing a program to calculate the total price of items in a shopping cart. The cart is a list of prices (e.g., [100, 50, 200]). Write the Python code to sum all the prices and print the total.
Scenario 2: You have a list of student scores. You want to give a bonus of 5 points to each student. Write the Python code to update the list with the bonus.
In groups, come up with a simple problem that can be solved with a loop and a list. For example, “List of 5 favourite foods” – write a Python program to print each food with a number. Each group presents their program.
Write a Python program that asks the user for 5 numbers, stores them in a list, and then prints the sum of all numbers. Use a loop to ask for the numbers.
while loop instead of a for loop?Build a To‑Do List Program: Write a Python program that allows the user to add tasks, view the list, and mark tasks as done. Use a list to store tasks. Include a loop to keep the program running until the user chooses to exit.
Write a Python program that takes a list of numbers and prints the largest and the smallest numbers. Test it with the list: [45, 78, 12, 90, 34].
Write a Python program that generates a list of 10 random numbers (between 1 and 100) and then counts how many are even and how many are odd. (Hint: use a loop and the modulo operator %).
Fill‑in‑the‑Blank: 1. loop, 2. while, 3. for, 4. list, 5. index, 6. append, 7. Python, 8. indentation, 9. print, 10. infinite.
True/False: 1F, 2T, 3F, 4F, 5T, 6T, 7F, 8F, 9F, 10T.
Multiple Choice: 1A, 2B, 3B, 4B, 5B, 6B, 7B, 8A, 9C, 10B, 11A, 12A, 13B, 14A, 15D.
In Module 4, you will learn about functions – a way to group code into reusable blocks. You will also learn about more advanced data structures. To prepare, think about tasks you repeat often – those are perfect candidates for functions. Bring your ideas to the next class!
Amazing work, Python coder! See you in Module 4! 🐍