0Pricing
Python For Kids · Lesson

If-Else Statements

Learn decision-making using if, else, and elif.

If-Else Statements is a free Python For Kids lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python For Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

If-Else Statements

Welcome to the Control Flow lesson! Today, we'll learn how to make decisions in your Python programs using if, else, and elif statements.

If-Else Statements — illustration 1

2

What are If-Else Statements?

If-Else statements allow your program to choose different paths based on certain conditions. It's like making decisions: "If this happens, do that; otherwise, do something else."

  • If: Checks a condition and executes code if it's true.
  • Else: Executes code if the if condition is false.
  • Elif: (Else If) Checks another condition if the previous if was false.

3

The If Statement

The if statement lets your program execute a block of code only if a certain condition is true.

Syntax:

if condition:
    # code to execute if condition is true

4

Example of an If Statement

Let's see how an if statement works with a simple example.

Example:

# Checks if the number is positive
number = 5
if number > 0:
    print("The number is positive.")

5

The Else Statement

The else statement lets your program execute a block of code if the previous if condition is false.

Syntax:

if condition:
    # code to execute if condition is true
else:
    # code to execute if condition is false

6

Example of If-Else Statement

Here's how to use both if and else statements together.

Example:

# Checks if the number is even or odd
number = 4
if number % 2 == 0:
    print("The number is even.")
else:
    print("The number is odd.")

7

The Elif Statement

The elif (short for "else if") statement allows you to check multiple conditions in sequence.

Syntax:

if condition1:
    # code to execute if condition1 is true
elif condition2:
    # code to execute if condition2 is true
else:
    # code to execute if none of the above conditions are true

8

Example of If-Elif-Else Statement

Let's create a program that categorizes a number as positive, negative, or zero.

Example:

# Categorizes the number
number = 0
if number > 0:
    print("The number is positive.")
elif number < 0:
    print("The number is negative.")
else:
    print("The number is zero.")

9

age = 16
if age >= 18:
    print("You are an adult.")
elif age >= 13:
    print("You are a teenager.")
else:
    print("You are a child.")

10

Great Job!

You've learned how to use if, else, and elif statements to make decisions in your Python programs. This allows your programs to respond differently based on various conditions. Keep practicing by creating your own decision-making programs!

If-Else Statements — illustration 10

Frequently asked questions

Is the “If-Else Statements” lesson free?

Yes — the full text of “If-Else Statements” is free to read here on the web, and the Python For Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python For Kids course, upgrade to CoddyKit PRO.

What will I learn in “If-Else Statements”?

Learn decision-making using if, else, and elif. You practise Python For Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python For Kids?

No prior experience is required. Python For Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “If-Else Statements” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python For Kids lesson?

Yes. Every Python For Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. If-Else Statements
  2. Loops in Python
  3. Nested Loops
  4. Break and Continue
← Back to Python For Kids