Python to Make Smart Decisions: From Daily Choices to If Statements

Lesson Overview

Learn how to make Python programs intelligent by teaching them decision-making skills. Discover how your daily decision-making process translates into powerful programming logic using if, elif, and else statements.

Lesson Content

A Typical College Morning Decision

Scenario: You wake up for college and look outside. It's cloudy and might rain.

Your thought process:

  • "Is it raining outside?"
  • If YES → Take umbrella and wear a jacket
  • If NO → Check if it looks cloudy
  • If cloudy → Take umbrella just in case
  • If sunny → Go without umbrella

What just happened? You automatically made decisions based on different conditions!

Programming Has the Same Decision-Making Logic!

Just like you make decisions based on weather conditions, programming languages can make decisions based on different conditions too!

Real life: "If it's raining, take umbrella"
Programming: "If user age is 18 or above, allow voting"

This decision-making ability is what makes programs intelligent and responsive!

What Are Conditions?

A condition is a statement that can be either True or False (Boolean).

Daily Life Examples:

  • "Is my phone battery below 20%?" → True or False
  • "Did I finish my assignment?" → True or False
  • "Is it past 6 PM?" → True or False
  • "Am I hungry?" → True or False

Every condition has only two possible answers: Yes (True) or No (False).

Why Are Conditions Useful and Important?

Think about your daily life - you constantly make decisions based on conditions, if the outcome is YES, you will reach in one way if not you may react differently or doesn't react at all:

  • If it's raining, I'll take an umbrella ,otherwise I will not take umbrella as it is un-necessary language

  • If I'm hungry, I'll eat food immediately , if not I will eat food after an hour

  • If it's the product is with in my budget, I'll will buy if not I will not buy it

Without conditions, programs would be "dumb" - they'd do the same thing every time!

Basic Conditional Statements in Python

1. Simple If Statement - "If This, Then That"

Real-world thinking: "If I'm hungry, I'll eat food"

hungry = True #Boolean --> True 
#Syntax for if :
# if <condition>:
if hungry:
    print("Let's eat something!")            # Indented, belongs to if
    print("Going to the cafeteria...")

How it works:

  • Python checks if the condition (hungry) is True
  • If True, it executes the indented code below
  • If False, it skips the indented code

wait ! did you observe there is a space or gap after the IF statement? this is called as Indentation

Why Indentation Matters in Python?
Tags: comparison-operators if-statements python

💬 Comments (0)

No comments yet. Be the first to share your thoughts!