🐍 Python for kids · Class 5 · Lesson 7 of 18 · Free
If Statements & Decisions
⏱ About 25 minutes · ▶ run real Python here — nothing to install · no sign-in
In this lesson you will
- Compare two values with ==, !=, >, <, >= and <=.
- Use if and else to choose between two actions.
- Use elif to pick one answer from many choices.
Every morning you make little decisions. If it is raining, you take an umbrella. If it is Monday, you pack your PT shoes. Today you will teach Python to make decisions just like you.
What is an if statement in Python?
So far, Python ran every line of your program. An if statement lets Python skip some lines.
You write if, then a question, then a colon. The lines under it are pushed in by four spaces. They run only when the answer to the question is yes.
Change the temperature to 30 below and run it again. Which line disappears?
▶temperature = 382if temperature > 35:3 print("It is very hot today!")4 print("Carry a water bottle.")5print("Have a nice day at school.")
No variables yet.
▌✏️ Change this code and run it yourself
It is very hot today! Carry a water bottle. Have a nice day at school.
💡 The last line is not pushed in, so it runs every time.
What are comparison operators in Python?
A comparison asks a yes-or-no question. Python answers with True or False. These two words are called Boolean values.
Python has six comparison signs. They are == (equal), != (not equal), > (greater) and < (smaller). The last two are >= (greater or equal) and <= (smaller or equal).
Remember: one = puts a value into a variable. Two == asks whether two things are equal.
True False True True
How does if else work in Python?
Often you want one action for yes and a different action for no. That is what else is for.
Python checks the condition once. Exactly one of the two blocks runs – never both, never neither.
Here, int() turns the typed answer into a number, so Python can compare it.
▶marks = int(input("Enter your marks: "))2if marks >= 40:3 print("You passed! Well done.")4else:5 print("Not this time. Keep practising!")6print("Result checked.")
No variables yet.
▌✏️ Change this code and run it yourself
Enter your marks: 42 You passed! Well done. Result checked.
How does elif choose between many options?
Sometimes there are more than two choices. elif means "else if". It asks another question when the earlier ones were False.
Python checks from the top down and stops at the first True condition. So the order of your questions matters.
The else at the end catches everything that did not match. It is like the "none of the above" option.
▶age = int(input("How old are you? "))2if age < 5:3 print("Zoo ticket: free")4elif age < 13:5 print("Zoo ticket: 20 rupees")6elif age < 60:7 print("Zoo ticket: 50 rupees")8else:9 print("Zoo ticket: 30 rupees")
No variables yet.
▌✏️ Change this code and run it yourself
How old are you? 11 Zoo ticket: 20 rupees
Why does indentation matter in Python?
Indentation means the spaces at the start of a line. Python uses it to know which lines belong to the if.
Lines pushed in under if form a block. A line that comes back to the left is outside the block, and always runs.
Use four spaces every time. Most code editors add them for you after a colon.
Let's go to the bus stop.
Can I compare words in Python?
Yes! == also works on strings. But it is very strict: "Mango" and "mango" are different to Python.
A smart trick is to use .lower() on the answer first. Then capital letters do not matter.
Which is the king of fruits? Mango Correct! Mango is the king.
💡 Comparing a string with a number never matches, so convert input() with int() when you need a number.
🤔 Predict the output
Think like Python: read the code and choose what it prints. You get the reason straight away.
Question 1. What does this print?
x = 7
if x > 5:
print("Big")
print("Done")Question 2. What does this print?
marks = 35
if marks >= 40:
print("Pass")
else:
print("Try again")Question 3. What does this print?
temp = 30
if temp > 35:
print("Hot")
elif temp > 25:
print("Warm")
elif temp > 15:
print("Nice")🧩 Your challenge
Build an Even-or-Odd checker. Ask the user for a number and tell them whether it is even or odd. Hint: an even number leaves remainder 0 when divided by 2.
Enter a number: 17 17 is an odd number.
⚠️ Common mistakes (and how to fix them)
❌ Wrong
score = 80
if score > 50
print("Great score!")SyntaxError: expected ':'
✅ Right
score = 80
if score > 50:
print("Great score!")Every if, elif and else line must end with a colon.
❌ Wrong
colour = "red"
if colour = "red":
print("Stop!")SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
✅ Right
colour = "red"
if colour == "red":
print("Stop!")One = stores a value; you need two == to ask whether two things are equal.
❌ Wrong
age = input("Age: ")
if age > 10:
print("You can ride!")TypeError: '>' not supported between instances of 'str' and 'int'
✅ Right
age = int(input("Age: "))
if age > 10:
print("You can ride!")input() always gives text, so wrap it in int() before comparing it with a number.
📌 Remember
- An if statement runs its block only when the condition is True.
- Comparisons (==, !=, >, <, >=, <=) give True or False.
- else runs when the if condition is False – exactly one block runs.
- elif adds more choices; Python stops at the first True condition.
- End if, elif and else with a colon, and indent the block by four spaces.
- Use = to store a value and == to compare two values.
Finished the quiz and the challenge?
Questions students ask
What is the difference between = and == in Python?
A single = stores a value in a variable, like age = 10. A double == compares two values and gives True or False, like age == 10.
What does elif mean in Python?
elif is short for "else if". It checks a new condition only when all the conditions above it were False. You can use as many elif lines as you need.
Do I always need an else after an if?
No, else is optional. Use it only when you want something to happen when the condition is False.
Why do I get an IndentationError in my if statement?
Python needs the lines inside an if to be pushed in, usually by four spaces. If the line after the colon starts at the left edge, Python shows an IndentationError.