Python Full Tutorial — Part 4

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.

Why Decision Making Matters

Login systems, payments, games, AI rules, validations — everything depends on conditions.

The if Statement

if checks a condition. If it is True, the code runs.

Basic if Example

age = 20

if age >= 18:
    print("You are allowed")
  

Python uses indentation, not brackets. This is non-negotiable.

The else Statement

else runs when the condition is False.

if else Example

age = 15

if age >= 18:
    print("You can vote")
else:
    print("You cannot vote")
  

The elif Statement

elif means "else if". It allows multiple conditions.

elif Example

marks = 72

if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")
elif marks >= 60:
    print("Grade C")
else:
    print("Fail")
  

Condition Evaluation Order

Python checks conditions top to bottom. First True condition executes.

Using Logical Operators

Multiple Conditions

age = 22
has_id = True

if age >= 18 and has_id:
    print("Entry allowed")
else:
    print("Entry denied")
  

Nested if Statements

One decision inside another decision.

Nested if Example

age = 20

if age >= 18:
    if age < 60:
        print("Adult")
    else:
        print("Senior")
else:
    print("Minor")
  

Common Beginner Mistakes

Real-World Example

Login Check

username = input("Enter username: ")
password = input("Enter password: ")

if username == "admin" and password == "1234":
    print("Login successful")
else:
    print("Invalid credentials")
  

Key Takeaway

If you understand if / else / elif, you understand the brain of programming.

Next part introduces loops — making Python repeat work automatically.

Disclaimer:
This tutorial is for educational purposes only. Practice regularly to build real programming skills.