Popcorn Hack 1: Simple Procedure Call & Parameters

Code Runner Challenge

Procedures Popcorn #1

View IPYNB Source
# CODE_RUNNER: Procedures Popcorn #1
def report_status(location, status):
  print("Status update from " + location + ": " + status)


# Calling report_status() two times with different arguments
report_status("Poway", "Clear")
report_status("Rancho Bernardo", "Under Investigation")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 2: Decomposition & Helper Procedures

Code Runner Challenge

Popcorn Hack 2 - Decomposition & Helper Procedures

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 2 - Decomposition & Helper Procedures
# Helper Procedure
def is_priority(incident_type):
  # Return True when the incident is a "Medical Emergency"
  return incident_type == "Medical Emergency"


# Outer Procedure
def process_report(location, incident_type):
  # Call is_priority() using incident_type and store in variable
  priority = is_priority(incident_type)

  # Print appropriate response based on returned priority
  if priority:
    print("PRIORITY: " + incident_type + " reported in " + location)
  else:
    print("STANDARD REPORT: " + incident_type + " reported in " + location)


# Call process_report() two times with different incident types
process_report("Poway", "Medical Emergency")
process_report("4S Ranch", "Traffic Jam")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack: Emergency Response Dispatcher

Code Runner Challenge

Homework Hack - Emergency Response Dispatcher

View IPYNB Source
# CODE_RUNNER: Homework Hack - Emergency Response Dispatcher


# Helper Procedure: Checks if an incident type requires priority response
def check_priority(incident_type):
  # Returns True for high-priority emergency types
  return (
      incident_type == "Medical Emergency"
      or incident_type == "Structure Fire"
      or incident_type == "Wildfire"
  )


# Outer Procedure: Handles response routing and dispatch logging
def dispatch_response(location, incident_type):
  # Call helper procedure to evaluate priority status
  is_urgent = check_priority(incident_type)

  # Use conditional logic to format and issue dispatch status
  if is_urgent:
    print(
        "EMERGENCY DISPATCH [URGENT]: Deploying immediate response for "
        + incident_type
        + " at "
        + location
        + "."
    )
  else:
    print(
        "EMERGENCY DISPATCH [ROUTINE]: Logging "
        + incident_type
        + " report for "
        + location
        + ". Standard patrol assigned."
    )


# Calling dispatch_response() at least three times across multiple locations & incident types
dispatch_response("Poway", "Medical Emergency")
dispatch_response("Rancho Bernardo", "Power Outage")
dispatch_response("4S Ranch", "Structure Fire")
dispatch_response("Sabre Springs", "Noise Complaint")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...