# prize35-4 Exercise 3: the highest fertiliser rate that keeps leaching under 10 kg/ha a year def run(fertiliser, years=10): soil = 50.0 leached_total = 0.0 for y in range(years): soil += 20 + fertiliser uptake = min(soil, 180.0) soil -= uptake leached = 0.4 * soil soil -= leached leached_total += leached return leached_total / years, uptake best = 0 for rate in range(0, 301, 5): leach, up = run(rate) if leach < 10: best = rate print("highest rate (step 5) with leaching under 10 kg/ha a year:", best) for rate in [best, best + 5, best + 10]: leach, up = run(rate) print(f"{rate:3d} kg/ha: leaches {leach:5.1f}") # Output: # highest rate (step 5) with leaching under 10 kg/ha a year: 165 # 165 kg/ha: leaches 9.2 # 170 kg/ha: leaches 13.5 # 175 kg/ha: leaches 17.7 # Reading it: leaching stays tiny until the crop is fully fed (about 160 kg/ha here), then climbs # fast. The extra fertiliser beyond the crop's need is not wasted quietly: it goes into streams and # groundwater, and each extra 5 kg/ha above the threshold keeps adding to the loss.