🐍 Python for kids · Class 6 · Lesson 1 of 18 · Free
If-Else Statements – Making Decisions
⏱ About 30 minutes · ▶ run real Python here — nothing to install · no sign-in
In this lesson you will
- Write if, elif and else blocks that choose one path out of many.
- Join conditions with and, or and not to make sharper rules.
- Put one if inside another to check things step by step.
At the cinema counter, the price depends on your age. At school, your grade depends on your marks. Every day, people make choices with rules. Today you will teach Python to make choices too.
How does an if-else statement work in Python?
An if statement asks a yes-or-no question. If the answer is True, Python runs the indented lines below it.
The else part is the plan B. It runs only when the condition is False.
Exactly one of the two blocks runs, never both. After that, Python continues with the next unindented line.
▶temperature = 382if temperature > 35:3 print("Too hot! Stay indoors and drink water.")4else:5 print("Nice weather. Go and play outside.")6print("Weather check done.")
No variables yet.
▌✏️ Change this code and run it yourself
Too hot! Stay indoors and drink water. Weather check done.
💡 Change 38 to 30 and run it again. Watch which block Python picks now.
How do I check more than two choices with elif?
Life often has more than two answers. elif means "else if". It lets you add as many extra checks as you need.
Python checks the conditions from top to bottom. It runs the first True block and skips all the rest.
That is why order matters. Put the strictest check, like marks >= 90, at the top.
Enter your marks out of 100: 78 Marks 78 -> Grade A2
How do I combine conditions with and, or and not?
Sometimes one check is not enough. and is True only when both sides are True.
or is True when at least one side is True. not flips True into False, and False into True.
Here a cinema gives a discount to children under 12 or seniors over 60. Weekend shows cost more.
▶age = 652day = "Sunday"3price = 2004if age < 12 or age > 60:5 price = price - 806if day == "Saturday" or day == "Sunday":7 price = price + 508print("Ticket price:", price, "rupees")
No variables yet.
▌✏️ Change this code and run it yourself
Ticket price: 170 rupees
What is a nested if statement?
A nested if is an if inside another if. The inner check runs only when the outer check is True.
Think of a school trip. First, did you bring the permission slip? Only then, did you pay the fee?
Each level of nesting adds four more spaces. The spaces show Python which block each line belongs to.
▶has_slip = True2fee_paid = 3003if has_slip:4 if fee_paid >= 500:5 print("You can go on the trip!")6 else:7 print("Please pay", 500 - fee_paid, "more rupees.")8else:9 print("Bring the signed permission slip first.")
No variables yet.
▌✏️ Change this code and run it yourself
Please pay 200 more rupees.
When should I use separate if statements instead of elif?
With if-elif, only one block can ever run. With separate if lines, every true check runs.
Use elif when the choices cannot all be true together, like grades. Use separate ifs for independent checks.
Below, a number is checked for three separate facts. More than one message can appear.
Enter a whole number: 120 120 is even. 120 is a multiple of 5. 120 is bigger than 100. Checks finished.
💡 Try 7. None of the checks is True, so only the last line prints.
Can I write a short if-else in one line?
Yes. When you only need to pick between two values, Python has a one-line form.
Read it like English: result is "Pass" if marks >= 33, else "Fail".
Use it for short, simple choices. For longer logic, the normal if-else block is easier to read.
Result: Pass The coach is worried
🤔 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 = 15
if x > 10:
print("big")
elif x > 5:
print("medium")
else:
print("small")Question 2. What does this print?
a = 4
b = 9
if a > 5 or b > 5:
print("yes")
else:
print("no")
if not a > 5:
print("small a")Question 3. What does this print?
rain = False
homework_done = True
if homework_done:
if rain:
print("Play indoors")
else:
print("Play cricket")
else:
print("Finish homework")🧩 Your challenge
Electricity bill! Ask for the units used. Up to 100 units cost 3 rupees each. Units 101 to 200 cost 5 rupees each. Every unit above 200 costs 8 rupees. Print the total bill.
Units used: 250 Total bill: 1200 rupees
⚠️ Common mistakes (and how to fix them)
❌ Wrong
marks = 95
if marks >= 33:
print("Pass")
elif marks >= 90:
print("Distinction")No error message – but 95 marks prints only Pass, never Distinction.
✅ Right
marks = 95
if marks >= 90:
print("Distinction")
elif marks >= 33:
print("Pass")Python stops at the first True check. Put the strictest condition first, or the later ones never get a turn.
❌ Wrong
day = "Monday"
if day == "Saturday" or "Sunday":
print("Holiday!")No error message – but it prints Holiday! even on Monday.
✅ Right
day = "Monday"
if day == "Saturday" or day == "Sunday":
print("Holiday!")or joins two full conditions. A non-empty string like "Sunday" alone counts as True, so the check always passes.
❌ Wrong
age = 12
if age >= 13:
print("Teen")
else:
print("Child")IndentationError: unindent does not match any outer indentation level
✅ Right
age = 12
if age >= 13:
print("Teen")
else:
print("Child")else must line up exactly with its if. Python uses spaces to know which blocks belong together.
📌 Remember
- if runs a block only when its condition is True; else is the plan B.
- elif adds more choices. Python runs only the first True block, so order matters.
- and needs both sides True, or needs one side True, and not flips the answer.
- A nested if is checked only when the outer if is True.
- Use elif for choices that exclude each other, and separate ifs for independent checks.
Finished the quiz and the challenge?
Questions students ask
What is the difference between if and elif in Python?
Every if starts a new decision and is always checked. An elif belongs to the if above it and is checked only when everything before it was False.
Can I have an if without an else?
Yes. If the condition is False and there is no else, Python simply skips the block and carries on.
How many elif blocks can I use?
As many as you need. With many checks, test the order carefully. Only the first True block runs.
Why does Python give IndentationError in my if statement?
The lines inside if, elif and else must be indented the same amount, usually four spaces. The words if, elif and else must line up with each other.