# Exercise 1: turn daily earthquake counts into an alert level def alert_level(count, background): ratio = count / background if ratio < 2: return "normal" if ratio < 5: return "advisory" if ratio < 15: return "watch" return "warning" BACKGROUND = 4 # typical quakes per day (invented) counts = [3, 5, 4, 9, 22, 61, 140] for day, n in enumerate(counts, start=1): print(f"day {day}: {n:4d} quakes ratio {n / BACKGROUND:5.1f} {alert_level(n, BACKGROUND)}") # day 1: 3 quakes ratio 0.8 normal # day 2: 5 quakes ratio 1.2 normal # day 3: 4 quakes ratio 1.0 normal # day 4: 9 quakes ratio 2.2 advisory # day 5: 22 quakes ratio 5.5 watch # day 6: 61 quakes ratio 15.2 warning # day 7: 140 quakes ratio 35.0 warning # Using a ratio to the volcano's own background means the same code works for a # quiet volcano and a restless one. The thresholds are invented for the exercise.