Popcorn Hack: Wildfire Dispatch Scanner

Skip safe alerts with continue, count and total the action alerts, and stop at the first critical alert with break. Safe cutoff is 3 (alerts below it are skipped) and the critical cutoff is 8.

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 should be skipped.
safe_cutoff = 3

# The loop should stop at this number or higher.
critical_cutoff = 8

# Counters and totals start at 0 because no alerts have been processed yet.
action_count = 0
safe_count = 0
total_action_score = 0
critical_found = False

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

    # If code reaches here, the alert needs action.
    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

# Final report: these lines explain what happened during the scan.
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 ...

Actual output: alerts 1 and 2 are skipped as safe; 4, 6, 3, and 9 need action; the scan stops at 9, so 5 is never checked. Final report: Safe alerts skipped 2, Action alerts 4, Total action score 22, Critical found True.

Explanation: continue skips only the current pass (used for safe alerts). break exits the whole loop (used for the first critical alert). The counters start at 0 and are updated with += inside the loop.

MCQ Check

The four MCQ questions are an interactive widget on the lesson page. Answer them there, then paste the copied result line below:

MCQ 3.08: <paste the copied result line, such as 4/4 | answers: A,B,A,B>

Homework Hack: Themed Loop-Based Checker

Theme: server load monitoring. Loads below 30 are skipped, loads of 85 or more are critical and stop the scan. Eight values, two thresholds, a for loop, continue, break, and five tracked summary values.

Code Runner Challenge

Homework Hack - themed loop-based checker

View IPYNB Source
# CODE_RUNNER: Homework Hack - themed loop-based checker
# Theme: server load monitoring (percent CPU use)
# Goal: skip safe values, count action values, total their scores, and stop at the first critical value.

server_loads = [22, 45, 18, 60, 33, 75, 90, 50]

# Values below safe_cutoff are skipped with continue
safe_cutoff = 30

# Values at or above critical_cutoff stop the loop with break
critical_cutoff = 85

# Summary variables
checked_count = 0
action_count = 0
skipped_count = 0
total_score = 0
critical_found = False

# Traverse every value until a critical value stops the scan
for value in server_loads:
    # Count every value the loop looks at
    checked_count += 1

    # Skip safe values (counted before continuing)
    if value < safe_cutoff:
        skipped_count += 1
        print(str(value) + ": safe, no action")
        continue

    # If code reaches here, this value needs action
    action_count += 1
    total_score += value
    print(str(value) + ": action needed")

    # Stop early if this value is critical
    if value >= critical_cutoff:
        critical_found = True
        print("Critical value found. Stop checking.")
        break

# Final report
print("Final Report")
print("Checked: " + str(checked_count))
print("Skipped: " + str(skipped_count))
print("Actions: " + str(action_count))
print("Total score: " + str(total_score))
print("Critical found: " + str(critical_found))
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Actual output: 22 and 18 are skipped, 45, 60, 33, 75, and 90 need action, and the scan stops at 90 (so the last value, 50, is never checked).

Final Report: Checked 7, Skipped 2, Actions 5, Total score 303, Critical found True.

Submission Notes

Lesson: Python 3.08 Iterations
MCQ 3.08: <paste the copied result line>
Popcorn: completed loop variable, thresholds, counters, continue, and break (yes)
Homework: list length = 8
Homework: thresholds = 30 (safe), 85 (critical)
Homework: final checked count = 7
Homework: final action count = 5
Homework: critical found = yes