Parent guide · 6 min read
Python if statements for kids: teaching a program to make a decision
Until a program can make a decision, it does the same thing every time. The if statement is what lets it check something and take one path or another: print "pass" or "try again", let the player in or keep the door shut. Children usually meet it soon after printing and variables, and it is where reading code starts to feel like reasoning. The ideas are simple, but the punctuation trips people up. This guide explains if, elif and else, walks one example through, and lists the slips to look for.

Try this tonight
4 things you can do at home
Start with decisions they already make
Ask "if it is raining, what do you take? Otherwise?" Then "if it is raining and cold?" Real-life choices map directly onto if, else and elif, and a child who can say the rule in plain words has already designed the program.
Write a one-decision program
Type age = 10, then if age >= 8: followed by an indented print("You can join the club"), then else: and an indented print("Come back when you are older"). Change age to 6 and run it again. One variable, two outcomes, and the child sees the program pick a branch.
Predict before running
For each new value, such as 8, 7 and 100, ask "which line will print?" before pressing run. The boundary value (8, where >= is true) is the interesting one, because it separates "greater than" from "greater than or equal to".
Read the error message aloud together
A missing colon, wrong indent or single equals sign produces a short message that names the line. Read it together and fix one thing at a time. Learning that the message points to the problem is as valuable as the if statement itself.
If, elif and else
The shape of an if statement is the word if, a condition, a colon, then indented lines that run only when the condition is true. Add else: and a second indented block for when it is false. In between you can add any number of elif conditions (short for "else if") for extra choices.
Python checks the conditions from the top and runs only the first branch that is true, then skips the rest. That order matters. If a score of 95 is tested first with score >= 50, a branch intended for "excellent" lower down never gets reached, so put the strictest test first.
A worked example: a grade message
Suppose score = 72. Write if score >= 90: print("Excellent"), then elif score >= 60: print("Pass"), then else: print("Try again"). Trace it. Is 72 >= 90? No, so skip. Is 72 >= 60? Yes, so print "Pass" and stop checking. The else branch never runs.
Now try 95. The first test is true, so it prints "Excellent" and never looks at the elif, even though 95 >= 60 is also true. Try 40: both tests are false, so the else runs and prints "Try again". Three values, three different outputs, one short program.
The slips: = versus ==, colons and indents
A single equals sign stores a value: age = 10. A double equals sign asks a question: age == 10 is true or false. Writing if age = 10: gives a syntax error because the program is being told to store where a question belongs. The mnemonic that works is "one equals gives, two equals asks".
The colon at the end of the if line and the indent on the lines below it are how Python knows which lines belong to the decision. If the print is not indented, Python complains or, worse, runs it every time. Also check that else lines up with its if, at the same indent, rather than sitting inside it.
Joining conditions with and, or, not
Real decisions often combine tests. if age >= 8 and age <= 12: is true only when both parts are true, so it picks out ages 8 to 12 inclusive. With or, one true part is enough: if day == "Saturday" or day == "Sunday": covers the weekend. And not flips true to false.
A good habit is to test a combined condition with edge values, such as 7, 8, 12 and 13, and say before each run what the answer should be. Writing the condition as two short pieces, then joining them, is easier than writing one long line at once.
Signs it’s time for outside help
When home help has done what it can
- Uses = where == is needed and cannot see why Python complains.
- Forgets the colon or the indent, repeatedly, on the same kind of line.
- Puts the strictest test last, so the earlier branch always wins.
- Cannot predict which branch runs for a given value.
- Writes the same print several times instead of using else.
- Can follow an example but freezes when asked to add one more choice.
Questions parents ask
FAQ
What is the difference between = and == in Python?
A single = stores a value in a variable, such as age = 10. A double == compares two values and gives true or false, as in age == 10. An if statement needs a comparison, so it uses ==.
What does elif mean?
It is short for "else if". It adds another condition to check only when the earlier ones were false. You can use as many elif lines as you need between if and else.
Do I always need an else?
No. An if on its own simply does nothing when the condition is false. Add else only when there is a different thing to do in that case.
Why does indentation matter in Python?
Python uses the spaces at the start of a line to decide which lines belong to the if. Lines indented under the if run only when the condition is true; lines at the left edge run regardless. Four spaces is the usual standard.
At what age can a child learn if statements?
Many children meet if and else around ages 8 to 10 in a beginner Python course, and some earlier. Comfort reading a true-or-false statement, such as "is 7 bigger than 5?", matters more than a particular age.
Further reading
Classes that fit
Live, 50–60 minutes, four learners at most or 1-on-1.
Not sure which is right for your child?
Tell us their age and what they have tried so far, and we will suggest where to start before you book anything.



