if (Decisions)Yesterday we learned how Python calculates. Today we learn how Python decides.
Calm rule: Python never guesses. It only follows True or False.
A Boolean is a value that is either True or False. There is nothing in between.
print(True) print(False)
Python creates True/False by comparing values.
> greater than< less than>= greater or equal<= less or equal== equal to!= not equal toprint(5 > 3) # True print(5 < 3) # False print(5 == 5) # True print(5 != 5) # False
Important: One equals = means “store”.
Two equals == means “compare”.
| Operator | Meaning | Example | Result |
|---|---|---|---|
> |
Greater than | 5 > 3 |
True |
< |
Less than | 5 < 3 |
False |
>= |
Greater or equal | 5 >= 5 |
True |
<= |
Less or equal | 4 <= 3 |
False |
== |
Equal to | 5 == 5 |
True |
!= |
Not equal | 5 != 3 |
True |
a = 10 print(a > 5) # True print(a == 10) # True
if (Decision time)
if means: “Run this code only when the condition is
True.”
age = 18
if age >= 18:
print("Eligible")
Python checks the condition. If it is True, it runs the indented block. If it is False, it skips the block.
Python uses spaces to decide what belongs inside
if.
if 5 > 3:
print("Correct indentation") # ✅
if 5 > 3:
print("Wrong indentation") # ❌ IndentationError
Ask the user for age. If age is 18 or more, print
"Eligible".
Optional challenge: Change the age and observe what happens.
print(10 > 50) print(10 == 10) print(10 != 10)
number = int(input("Enter a number: "))
if number > 50:
print("Big number!")
age = int(input("Enter your age: "))
if age >= 18:
print("Eligible")
Tip: When you see an if, ask: “What condition becomes
True/False?”
First run may take a few seconds. Input will appear as browser prompts.
Output will appear here…
Note: If the condition is False, the indented block is skipped, but the program continues.
Enter values for a and b. Python-style
comparisons update instantly.