Code viewer for World: Control Flow: Nested Condi...
"""
Topic: Control Flow: Nested Conditions
Purpose: Learn how to use if statements inside other if statements
Output: Shows how Python evaluates conditions step-by-step
"""

# -----------------------------
# 1. Example variables
# -----------------------------
age = 22
has_id = True

# -----------------------------
# 2. Basic nested if statement
# -----------------------------
# An if statement inside another if
if age >= 18:
    print("You are an adult.")

    if has_id:
        print("You can enter the club.")
    else:
        print("You need an ID to enter.")

# -----------------------------
# 3. Nested if with else
# -----------------------------
# The outer else runs if the first condition is False
if age >= 18:
    print("Access level: Adult")

    if age >= 21:
        print("You can legally drink.")
    else:
        print("You cannot legally drink yet.")
else:
    print("Access level: Minor")

# -----------------------------
# 4. Nested conditions with multiple checks
# -----------------------------
score = 78
attendance = 85

if score >= 60:
    print("You passed the exam.")

    if attendance >= 75:
        print("You are eligible for the certificate.")
    else:
        print("Attendance too low for certification.")
else:
    print("You failed the exam.")

# -----------------------------
# 5. Notes
# -----------------------------
# 1. Nested conditions are if statements inside other if blocks.
# 2. Indentation is critical for correct logic.
# 3. Inner conditions run only if outer conditions are True.
# 4. Too much nesting can make code hard to read.
# 5. Deep nesting can often be simplified using logical operators.