# Exercise 2: crossing windows for a glacier stream at three flow limits, plus the daily peak import math def flow(hour): return 2.0 + 3.0 * max(0.0, math.sin(math.pi * (hour - 6) / 12)) print(f"Peak flow {max(flow(h) for h in range(24)):.1f} m3/s at {max(range(24), key=flow):02d}:00") for limit in (2.5, 3.5, 4.5): safe = [h for h in range(24) if flow(h) <= limit] daytime = [h for h in safe if 6 <= h <= 20] print(f"Limit {limit} m3/s: {len(safe):2d} safe hours a day, {len(daytime)} of them between 06:00 and 20:00") # Peak flow 5.0 m3/s at 12:00 # Limit 2.5 m3/s: 13 safe hours a day, 4 of them between 06:00 and 20:00 # Limit 3.5 m3/s: 17 safe hours a day, 8 of them between 06:00 and 20:00 # Limit 4.5 m3/s: 19 safe hours a day, 10 of them between 06:00 and 20:00