Exercise 3 solution def step(p, w_AA, w_Aa, w_aa): q = 1 - p mean_w = p * p * w_AA + 2 * p * q * w_Aa + q * q * w_aa return (p * p * w_AA + p * q * w_Aa) / mean_w for s in (0.2, 0.05): q = 0.5 gens = 0 while q >= 0.1: p = step(1 - q, 1.0, 1.0, 1 - s) q = 1 - p gens += 1 print(s, gens, round(q, 4)) q = 0.5 for _ in range(100): q = 1 - step(1 - q, 1.0, 1.0, 0.8) print(round(q, 4)) Output: 0.2 50 0.0983 0.05 203 0.0996 0.051 Reading it: with a 20% disadvantage it takes 50 generations for q to fall below 0.1; with a 5% disadvantage it takes 203, roughly four times longer for a four times weaker disadvantage. After 100 generations with s = 0.2 the allele is still at about 5%, which shows how slowly selection removes a recessive allele once it is rare.