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?

In Python, indentation (that is, the spaces at the start of a line) isn’t just for making code look pretty—it’s actually how Python knows which statements belong to which block.
Whenever you see a colon (:) at the end of a line (like after if, elif, or else), the code that comes next must be indented.

If you forget to indent, or if you use different numbers of spaces, Python will show you an IndentationError.

2. If-Else Statement - "If This, Then That; Otherwise, Do This"

Real-world thinking: "If I have money, buy lunch; otherwise, eat at home"

money = 50
lunch_price = 40
if money >= lunch_price:
    print("Great! I can buy lunch")
    print("Going to the restaurant")
else:
    print("Not enough money for lunch")
    print("I'll eat at home")

3. If-Elif-Else Statement - "Multiple Choices"

Real-world thinking: Weather-based clothing decision

# Python version
weather = "rainy"
if weather == "sunny":
    print("Wear light clothes and sunglasses")
elif weather == "rainy":
    print("Take umbrella and wear jacket")
elif weather == "cold":
    print("Wear warm clothes and jacket")
else:
    print("Check weather app for guidance!")

You've might have spotted something important! Although money >= lunch_price appears to be mathematical comparison, conditions depend on Boolean values to function. The key insight is that mathematical comparisons don't just check relationships - they produce Boolean results. Python evaluates that comparison and returns either True or False, giving the condition exactly what it needs to decide which code to run.

Comparison Operators - Making Comparisons

Just like in mathematics, we can compare values using special symbols:

OperatorMeaningMath SymbolExampleResult
==Equal to=age == 18True if age is exactly 18
!=Not equal toname != "admin"True if name is not "admin"
<Less than<score < 50True if score is below 50
>Greater than>marks > 90True if marks exceed 90
<=Less than or equalage <= 25True if age is 25 or below
>=Greater than or equalsalary >= 30000True if salary is 30000 or above

Understanding Boolean Values

In Python, conditions result in Boolean values: True/False

# Boolean examples
is_student = True
has_money = False
age = 20
print(age > 18)    # Output: True
print(age == 15)   # Output: False
print(is_student)  # Output: True
# Using booleans directly in if statements
if is_student:
    print("Student discount available!")
if not has_money:  # 'not' reverses the boolean
    print("Cannot buy lunch")

Important Note: = vs ==

  • = → Assignment (giving a value): age = 20
  • == → Comparison (checking equality): age == 20

Practical Examples:

# Age verification
age = 17
if age >= 18:
    print("You can vote!")
else:
    print("You cannot vote yet as your age is less than 18 years")
# Grade checking
score = 85
if score >= 90:
    print("Grade: A")
elif score >= 80:
    print("Grade: B")
elif score >= 70:
    print("Grade: C")
else:
    print("Grade: F")

Practical Decision-Making Examples

Example 1: College Admission System

# College admission checker
percentage = float(input("Enter your 12th grade percentage: "))
if percentage >= 95:
    print("Congratulations! Direct admission to top college!")
elif percentage >= 85:
    print("Eligible for good colleges")
elif percentage >= 75:
    print("Eligible for average colleges")
else:
    print("Need to improve scores for college admission")

💡 Key Takeaways

  • Conditions are everywhere - both in real life and programming
  • If statements make programs intelligent and responsive
  • Comparison operators (==, !=, <, >, <=, >=) help us compare values
  • if-elif-else handles multiple conditions
  • Indentation matters - Python uses it to group code blocks
  • Boolean values (True/False) are the foundation of decision-making

Coming Up Next

Now that you’ve learned how to make smart choices with if, elif, and else, it’s time to look under the hood of decision-making.
In your next lesson, you’ll discover:

  • How Boolean compliments with If-else ladder? The magical data type that powers every decision—just True or False!
  • How computers combine decisions: Mix and match checks using and, or, and not to build super-smart code.