Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← PYTHON FUNDAMENTALS LEVEL ONE PROFESSIONAL · Lesson 5 of 8

Module Four

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
5
Module 4 · Control Flow · Python for 13-year-olds

🔀 Module 4 · Control Flow

🧑‍🎓 for 13-year-olds decisions & loops · 50 min
🚦 if · elif · else · while · for

Time to give your programs a brain! 🧠 In Modules 1–3, your code ran in a straight line. Now you’ll make it choose paths (like “if the player has a key, open the door”) and repeat actions (like “keep asking until the answer is correct”). This is called control flow — and it’s where coding gets really fun!

1

Making decisions with if 🚦

The if statement runs some code only when a condition is True. The condition is just a boolean expression (remember Module 3!). Notice the colon : and the indentation (4 spaces) — they’re required!

age = 13
if age >= 13:
print("You can join the teen club! 🎉")

# This line runs no matter what
print("Program finished.")

🧭 How it flows

Check condition → True → run the indented code → False → skip it
⚠️ Indentation is law! Python uses spaces (not { }) to know which lines belong inside the if. Use 4 spaces every time.
2

Two paths with if / else 🔀

What if you want something to happen when the condition is False? Add an else block. Only one of the two blocks will run.

temperature = 28
if temperature > 25:
print("It's hot! Grab ice cream 🍦")
else:
print("Nice weather — go outside! 🌳")

🧭 How it flows

Condition True? → Yes → if-block | No → else-block
3

Many choices with elif 🎚️

elif means “else if”. Use it to test more conditions in order. Python checks each one from top to bottom and runs the first match it finds, then skips the rest.

score = 85
if score >= 90:
print("Grade: A 🥇")
elif score >= 80:
print("Grade: B 🥈")
elif score >= 70:
print("Grade: C 🥉")
else:
print("Keep practising! 💪")
📏 Order matters! Always put the strictest condition first. If you checked >= 70 first, even a 95 would get a C!
4

Repeat with while 🔁

A while loop keeps running as long as its condition is True. Perfect for things like “keep asking until the user types the right password”.

countdown = 5
while countdown > 0:
print(f"{countdown}...")
countdown -= 1
print("Liftoff! 🚀")
⚠️ Danger zone: If the condition never becomes False, you get an infinite loop! Always make sure something inside the loop changes the condition (like countdown -= 1).
5

Count with for & range() 🔢

A for loop repeats code a set number of times. The range() function generates a sequence of numbers for you. It’s cleaner than while when you know how many times to loop.

CodeGives you
range(5)0, 1, 2, 3, 4
range(1, 6)1, 2, 3, 4, 5
range(0, 10, 2)0, 2, 4, 6, 8
# Times table for 3
for i in range(1, 6):
print(f"3 x {i} = {3 * i}")

# Loop through a string
for letter in "PYTHON":
print(letter)
6

Loop control: break & continue 🚪

Sometimes you need to exit a loop early (break) or skip one turn (continue). Here’s how they work inside a game-style loop:

for level in range(1, 11):
if level == 5:
print("Boss level! Stopping here 😱")
break
if level % 2 == 0:
continue # skip even levels
print(f"Level {level} complete ✅")
🎮 Think of it like: break = quit the game. continue = skip to the next level.
7

Put it all together 🧩

Here’s a tiny number-guessing game that uses while, if/elif/else, and break. (We’ll use input() here — it asks the player to type something!)

secret = 7
tries = 0

while True:
guess = int(input("Guess a number 1-10: "))
tries += 1
if guess == secret:
print(f"Correct! You got it in {tries} tries 🎉")
break
elif guess < secret:
print("Too low! ⬆️")
else:
print("Too high! ⬇️")
🧪 Try it! Save this as guess.py and run it. Notice how the loop keeps going until break runs.

🏆 Mini challenge: FizzBuzz (the classic!)

FizzBuzz is a famous coding challenge. Create a file called fizzbuzz.py. Loop through the numbers 1 to 20 and:

  • If the number is divisible by 3, print "Fizz" (use %).
  • If it’s divisible by 5, print "Buzz".
  • If it’s divisible by both 3 and 5, print "FizzBuzz".
  • Otherwise, just print the number.
# Starter code – complete the loop!
for n in range(1, 21):
# Your if / elif / else logic here
pass # replace pass with your code

💡 Hint: Check for “both” first using n % 3 == 0 and n % 5 == 0. Bonus: use continue to skip printing the number in some cases!

🧑‍🏫 Remember: Colons and indentation make or break your loops. If something errors, check your spaces first!

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→