Popcorn Hack

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]

# Pick the cutoff for safe alerts. Alerts below this number should be skipped.
safe_cutoff = 4

# Pick the cutoff for critical alerts. 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:
    # If the alert is safe, 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.
    # Count this action alert and add its score to the running total.
    action_count += 1
    total_action_score += alert
    print("Alert " + str(alert) + ": action needed")

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

# Final report: these lines should 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 ...

Code Runner Challenge

Homework Hack - themed loop-based checker

View IPYNB Source
# CODE_RUNNER: Homework Hack - themed loop-based checker
# Theme: Air-quality readings.
# Goal: skip safe values, count action values, total their scores, and stop at the first critical value.

# Fill in at least 8 numbers for your scenario.
aqi_readings = [45, 30, 60, 20, 110, 155, 40, 12]

# Values below safe_cutoff should be skipped with continue.
safe_cutoff = 50

# Values at or above critical_cutoff should stop the loop with break.
critical_cutoff = 150

# Summary variables. Keep these, but make sure your loop updates them correctly.
checked_count = 0
action_count = 0
skipped_count = 0
total_score = 0
critical_found = False

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

    # Skip safe values. Remember to count them before continuing.
    if value < safe_cutoff:
        skipped_count += 1
        print("AQI " + str(value) + ": safe, no action")
        continue

    # If code reaches here, this value needs action.
    # Count it and add it to the running total.
    action_count += 1
    total_score += value
    print("AQI " + str(value) + ": action needed")

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

# Final report. These labels should make sense for your theme.
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 ...