Exercise 2.4
Production Alert System
Write production_alert(well_name, current_rate, previous_rate, water_cut) that returns one of the alert strings below, checked in this priority order:
"Critical: Watered Out": water_cut > 0.90"Critical: Rapid Decline": current_rate dropped more than 30% below previous_rate"Warning: High Water Cut": water_cut > 0.75"Warning: Significant Decline": current_rate dropped more than 15% below previous_rate"Info: Rate Increase": current_rate rose by more than 20%"Normal": none of the above
well_name is informational only. You can include it in the returned string if you like (the grader matches with startswith, so prefixes matter and suffixes don't). Apply your function to a portfolio of wells and verify that the order of if/elif statements matters: a well at 4 bopd with 95% water cut should be classified as Watered Out before Rapid Decline.
> Think about it: what additional data would you want before > escalating any of these alerts to a workover decision? When does an > alert mean "investigate" vs "act"?
Stuck? Reveal hints one at a time — they progress from nudge to near-solution.
visibilityReveal reference solutionexpand_more
Try solving it yourself first — the hints walk you through it. The solution below is one valid approach; yours may differ and still be correct.
def production_alert(well_name, current_rate, previous_rate, water_cut):
change = (current_rate - previous_rate) / previous_rate
if water_cut > 0.90:
return f"Critical: Watered Out ({well_name})"
if change < -0.30:
return f"Critical: Rapid Decline ({well_name})"
if water_cut > 0.75:
return f"Warning: High Water Cut ({well_name})"
if change < -0.15:
return f"Warning: Significant Decline ({well_name})"
if change > 0.20:
return f"Info: Rate Increase ({well_name})"
return f"Normal ({well_name})"
for w, cur, prev, wc in [
("OD-001", 900, 1000, 0.95),
("OD-002", 600, 1000, 0.50),
("OD-003", 1000, 1000, 0.80),
("OD-004", 1250, 1000, 0.10),
("OD-005", 1000, 1000, 0.10),
]:
print(production_alert(w, cur, prev, wc))
lockCopying code is a Full Access feature.