Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Dev simulates Tt with tt using random.choice(mum) + random.choice(mum), where mum = "Tt" and dad = "tt". On average, what percent of the children does his code make short? What should it be?
random.choice(parent) picks one gamete at random, and one choice from each parent makes a child. Counter(baby(...) for _ in range(n)) makes and counts n children. random.seed(k) repeats the same random numbers. A few plants wander far from the expected share; many plants settle near it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The bug. Both letters come from Tt, so the code really crosses Tt with Tt. One box in four is tt: %.
Step 2. The fix. Take one letter from each parent: random.choice(mum) + random.choice(dad).
Step 3. The right share. Tt with tt gives Tt, Tt, tt and tt: % short.
Answer: % with the bug; % when fixed.
Log in to join the discussion.
Loading…