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]

# Cutoff for safe alerts. Alerts below 3 are skipped.
safe_cutoff = 3

# Cutoff for critical alerts. Stop at 8 or higher.
critical_cutoff = 8

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

# Loop through the alert list
for alert in alerts:
  # Skip safe alerts
  if alert < safe_cutoff:
    safe_count += 1
    print("Alert " + str(alert) + ": safe, skipping")
    continue

  # Process action alerts
  action_count += 1
  total_action_score += alert
  print("Alert " + str(alert) + ": action needed")

  # Stop if critical alert found
  if alert >= critical_cutoff:
    critical_found = True
    print("Critical alert found - stopping scan")
    break

# Final report
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

MCQ Result: 4/4 answers: A,B,A,B

Homework Hack: Server CPU Load Checker

Code Runner Challenge

Homework Hack - themed loop-based checker

View IPYNB Source
# CODE_RUNNER: Homework Hack - themed loop-based checker
# Theme: Server Cluster CPU Load Monitoring System (%)
# Goal: Skip normal load, track elevated load, and halt checking on critical overheat.

server_loads = [18, 42, 25, 68, 55, 94, 72, 30]

safe_cutoff = 40  # Below 40% CPU load is safe/normal
critical_cutoff = 85  # 85% CPU load or above is critical

checked_count = 0
action_count = 0
skipped_count = 0
total_score = 0
critical_found = False

for value in server_loads:
  checked_count += 1

  # Skip safe/normal CPU loads
  if value < safe_cutoff:
    skipped_count += 1
    print(str(value) + "%: safe, no action")
    continue

  # Process elevated CPU load requiring attention
  action_count += 1
  total_score += value
  print(str(value) + "%: action needed (elevated load)")

  # Stop checking if a critical load spike occurs
  if value >= critical_cutoff:
    critical_found = True
    print("Critical value found. Stop checking.")
    break

# Final report
print("\nFinal 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 ...

Submission Notes

Lesson: Python 3.08 Iterations MCQ 3.08: 4/4 | answers: A,B,A,B Popcorn: completed loop variable, thresholds, counters, continue, and break (yes) Homework: list length = 8 Homework: thresholds = safe_cutoff: 40, critical_cutoff: 85 Homework: final checked count = 6 Homework: final action count = 4 Homework: critical found = yes