15

Lesson 15 of 20 · Conditionals

Conditionals — Part 4

If–else: make decisions based on conditions. This is part 4 of 20.

What you'll learn

You will learn how if/else lets code make decisions based on whether something is true or false.

Steps

  1. 1Read the code. x is set to True. The 'if x:' line checks: is x true? Since it is, the code prints 'Yes!'
  2. 2The 'else' block only runs when the condition is NOT true. Since x IS True, the 'No!' line gets skipped entirely.
  3. 3If x were False instead, the computer would skip 'Yes!' and print 'No!' instead. One condition, two possible paths!
  4. 4Conditions let programs make decisions — like a fork in the road. 'if' goes one way, 'else' goes the other.

Key Terms

Condition
A check that can be true or false. The program chooses what to do based on it.
if
A keyword that means 'when this is true, do this block of code.'
else
A keyword that means 'otherwise, when the if is not true, do this block instead.'
Python 3
Output
Loading Python... This may take a few seconds.

Your code runs only in your browser. No code is sent to any server. Stay safe and have fun learning!

🖨️

Checkout complete lesson on Conditionals for 3rd Grade

Get the full Conditionals track as a printable PDF — all lessons, worksheets, and answer keys.

View in Shop

Your Cart (0)

Your cart is empty

Browse our shop to find activities your kids will love