Popcorn Hack 1: Simple Procedure Call & Parameters

def report_status(location, status):
    print(f"Status update from {location}: {status}")

report_status("Del Norte High", "All clear")
report_status("PATH San Diego", "Supplies delivered")
Status update from Del Norte High: All clear
Status update from PATH San Diego: Supplies delivered

Popcorn Hack 2: Decomposition & Helper Procedures

# Helper Procedure
def is_priority(incident_type):
    return incident_type == "Medical Emergency"

# Outer Procedure
def process_report(location, incident_type):
    priority = is_priority(incident_type)
    if priority:
        print("PRIORITY: " + incident_type + " reported in " + location)
    else:
        print("STANDARD REPORT: " + incident_type + " reported in " + location)

process_report("Poway", "Medical Emergency")
process_report("Escondido", "Power Outage")
PRIORITY: Medical Emergency reported in Poway
STANDARD REPORT: Power Outage reported in Escondido

Homework Hack: Emergency Response Simulation

# Helper procedure returning a Boolean
def check_priority(incident_type):
    return incident_type in ["Medical Emergency", "Fire", "Earthquake"]

# Outer procedure handling the dispatch
def dispatch_response(location, incident_type):
    is_urgent = check_priority(incident_type)
    
    if is_urgent:
        print(f"URGENT DISPATCH: Routing emergency services to {location} for a {incident_type}!")
    else:
        print(f"STANDARD DISPATCH: Logging {incident_type} in {location} for routine follow-up.")

# Called at least three times with different locations and types
dispatch_response("Escondido", "Medical Emergency")
dispatch_response("Del Norte", "Noise Complaint")
dispatch_response("Poway", "Fire")
URGENT DISPATCH: Routing emergency services to Escondido for a Medical Emergency!
STANDARD DISPATCH: Logging Noise Complaint in Del Norte for routine follow-up.
URGENT DISPATCH: Routing emergency services to Poway for a Fire!