Elena' s AI Blog

Making Decisions: The Fork in the Road

05 Jan 2026 / 2 minutes to read

Elena Daehnhardt


Lesson 4 of 10 40%


TL;DR: Use `if` to check a condition. If it is true, the indented code runs. If not, it is skipped. This is how computers think.

Computers Needs Rules

Life is full of choices. If it is raining, take an umbrella. If I am hungry, eat a cookie.

Computers can make these choices too, but we have to give them the rules. We use the magic word if.

The if Statement

age = 10

if age > 7:
    print("You are old enough to play!")

The Anatomy of a Decision

  1. if: The keyword.
  2. age > 7: The check (The Question). Is age bigger than 7?
  3. :: The colon (Essential! Don’t forget it).
  4. Indentation: The next line is pushed in (indented).

Rule: The indented code only runs if the answer is YES (True).

If age was 5, the computer would say nothing.

The else Statement (Or Else!)

What if we want to say something when the answer is NO?

password = input("What use the secret password? ")

if password == "python":
    print("Access Granted. Welcome, Master.")
else:
    print("Access Denied! Run away!")

Note: We use == (two equals signs) to ask “Are these the same?”. One = is for assigning values.

Common Checks

  • a > b : Is a bigger than b?
  • a < b : Is a smaller than b?
  • a == b: Are they equal?
  • a != b: Are they NOT equal?

Try It Yourself: The Bouncer

Write a program that asks for the user’s age.

  • If they are over 18, say “You can drive a car.”
  • Else, say “You keep riding your bike.”
age = input("How old are you? ")
# Trick: Convert text to number using int()
age_number = int(age)

if age_number > 18:
    print("Vroom vroom!")
else:
    print("Pedal pedal!")

This post is part of the Python Basics for Kids series, based on “Python for Kids from 8 to 88”.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2026) 'Making Decisions: The Fork in the Road', daehnhardt.com, 05 January 2026. Available at: https://daehnhardt.com/courses/book0/04-making-decisions/
Course Library