Popcorn Hack: Wildfire Dispatch Scanner

Alerts below 3 are safe and skipped with continue. Alerts of 9 or higher are critical and stop the scan with break. Every other alert is counted and added to the running total.

Code Runner Challenge

Popcorn Hack - wildfire dispatch scanner

View IPYNB Source
# CODE_RUNNER: Popcorn Hack - wildfire dispatch scanner
# Theme: The SFSRC team scans wildfire alert levels from different zones.
# Goal: skip safe zones, count response zones, total their alert scores, and stop at the first critical zone.

alerts = [1, 4, 2, 6, 3, 9, 5]

# Alerts below this number are safe and get skipped
safe_cutoff = 3

# Alerts at this number or higher are critical and stop the scan
critical_cutoff = 9

action_count = 0
safe_count = 0
total_action_score = 0
critical_found = False

for alert in alerts:
    # Safe alert: count it, print it, and skip to the next alert
    if alert < safe_cutoff:
        safe_count += 1
        print("Alert " + str(alert) + ": safe, skipping")
        continue

    # This alert needs action: count it and add it to the running total
    action_count += 1
    total_action_score += alert
    print("Alert " + str(alert) + ": action needed")

    # Critical alert: mark it and stop the scan
    if alert >= critical_cutoff:
        critical_found = True
        print("Critical alert found - stopping scan")
        break

print("Safe alerts skipped: " + str(safe_count))
print("Action alerts: " + str(action_count))
print("Total action score: " + str(total_action_score))
print("Critical found: " + str(critical_found))
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

The 5 at the end of the list is never checked, because break stops the scan at the critical 9.

Homework Hack: School Server Load Monitor

My checker watches the CPU load (percent) on a school web server during the school day:

  • Loads below 50% are healthy, so they are skipped with continue.
  • Loads 50% and up need attention, so they are counted and added to a running total.
  • A load of 95% or higher is critical, so the scan stops with break so the tech team can respond.

The report tracks how many readings were checked, skipped, and flagged, the total flagged load, and whether a critical load was found.

Code Runner Challenge

Homework Hack - school server load monitor

View IPYNB Source
# CODE_RUNNER: Homework Hack - school server load monitor
# Theme: CPU load readings (percent) from a school web server, taken every 10 minutes.
# Goal: skip healthy loads, count and total high loads, and stop at the first critical load.

server_loads = [35, 62, 48, 71, 20, 88, 97, 55, 40]

# Loads below this are healthy, so the checker skips them
healthy_cutoff = 50

# Loads at or above this are critical, so the checker stops
critical_cutoff = 95

checked_count = 0
flagged_count = 0
healthy_count = 0
total_flagged_load = 0
critical_found = False

for load in server_loads:
    # Every reading the loop looks at is counted
    checked_count += 1

    # Healthy load: count it and skip to the next reading
    if load < healthy_cutoff:
        healthy_count += 1
        print(str(load) + "% load: healthy, no action")
        continue

    # High load: count it and add it to the running total
    flagged_count += 1
    total_flagged_load += load
    print(str(load) + "% load: high, alert the tech team")

    # Critical load: stop checking so the team can respond right away
    if load >= critical_cutoff:
        critical_found = True
        print("Critical load found. Stop checking.")
        break

print("Final Server Report")
print("Readings checked: " + str(checked_count))
print("Healthy readings skipped: " + str(healthy_count))
print("High-load alerts: " + str(flagged_count))
print("Total flagged load: " + str(total_flagged_load) + "%")
print("Critical load found: " + str(critical_found))
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...