Junior Codes
Message Harbour

Python if, elif and else for Kids

Choose between many options, with a fallback for everything else.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

if / elif / else, explained simply

A plain if handles one situation. Real decisions often have several: if it is cold wear a coat, if it is mild wear a jumper, otherwise wear a T-shirt.

elif is short for "else if". Python checks the if first, then each elif in order, and runs the first block whose question is True. It skips all the rest.

else comes last and has no question. It catches every case the earlier checks did not. That makes sure your program always has an answer.

Example: Dress for the weather

temperature = 18
if temperature < 10:
    print("Wear a warm coat")
elif temperature < 22:
    print("A jumper will do")
else:
    print("T-shirt weather!")

Output

A jumper will do

Try this

  • Try temperatures of 5, 21 and 30. Which block runs each time?
  • Swap the order of the first two checks and find the temperature that now gives a silly answer.
  • Add another elif for rainy days using a second variable.

Practise it in Wonderwild

“Build a weather wardrobe”

Mission 12 in Message Harbour, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Does the order of elif checks matter?+

Yes. Python stops at the first True check, so put the most specific conditions first. Otherwise an earlier, broader check can catch cases it should not.

How many elif lines can I have?+

As many as you need. If you find yourself writing a very long chain, a dictionary or a list can sometimes be tidier.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course