Popcorn Hack - wildfire dispatch scanner

Code Runner Challenge

Popcorn Hack 1

View IPYNB Source
%%python

# CODE_RUNNER: Popcorn Hack 1 

# 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 = 7

# 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
    elif safe_cutoff < alert < critical_cutoff:
        # 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 ...

MCQ Check

MCQ 3.08 Iterations: 4/4 | answers: A,B,A,B

Homework Hack

Code Runner Challenge

Homework Hack

View IPYNB Source
%%python

# CODE_RUNNER: Homework Hack

# Theme: Choose your own monitoring system.
# Examples: wildfire alerts, server loads, battery levels, quiz scores, or air-quality readings.
# Goal: skip safe values, count action values, total their scores, and stop at the first critical value.

# TODO: Rename values if you want a stronger theme, such as server_loads or battery_levels.
# TODO: Fill in at least 8 numbers for your scenario.
values = [2, 5, 3, 8, 1, 7, 4, 6]

# TODO: Values below safe_cutoff should be skipped with continue.
safe_cutoff = 4

# TODO: Values at or above critical_cutoff should stop the loop with break.
critical_cutoff = 7

# 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

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

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

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

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

# Final report. These labels should make sense for your theme.
print("Final Report for Mini Battery Voltage")
print("Checked: " + str(checked_count))
print("Skipped: " + str(skipped_count))
print("Actions: " + str(action_count))
print("Total score: " + str(total_score))
print("Critical status found: " + str(critical_found))


Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...