Till now we learned data, operators, and expressions. Now comes the most important concept: decision making.
Programs are powerful because they can choose different paths based on conditions.
Login systems, payments, games, AI rules, validations — everything depends on conditions.
if Statement
if checks a condition.
If it is True, the code runs.
age = 20
if age >= 18:
print("You are allowed")
Python uses indentation, not brackets. This is non-negotiable.
else Statement
else runs when the condition is False.
age = 15
if age >= 18:
print("You can vote")
else:
print("You cannot vote")
elif Statement
elif means "else if".
It allows multiple conditions.
marks = 72
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 60:
print("Grade C")
else:
print("Fail")
Python checks conditions top to bottom. First True condition executes.
age = 22
has_id = True
if age >= 18 and has_id:
print("Entry allowed")
else:
print("Entry denied")
One decision inside another decision.
age = 20
if age >= 18:
if age < 60:
print("Adult")
else:
print("Senior")
else:
print("Minor")
= instead of ==
username = input("Enter username: ")
password = input("Enter password: ")
if username == "admin" and password == "1234":
print("Login successful")
else:
print("Invalid credentials")
If you understand if / else / elif,
you understand the brain of programming.
Next part introduces loops — making Python repeat work automatically.