Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Kiran writes def phenotype(g): return "tall" if g == "TT" else "short" and counts the phenotypes of the four boxes ['TT', 'Tt', 'Tt', 'tt']. How many tall and how many short does the program report? Fix the function.
A gamete is one letter of a parent: list("Tt") gives ['T', 't']. A child is "".join(sorted(a + b)), so the dominant capital letter comes first. Two loops over the parents' letters fill the Punnett square, and Counter counts the genotypes or the phenotypes. Tt with Tt gives 1 TT : 2 Tt : 1 tt, which is 3 tall to 1 short.
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. Run it in your head. Only the first box equals "TT". The function calls the other three short.
Step 2. The count. tall and short: the ratio upside down.
Step 3. The fix. One T is enough, so test for it: return "tall" if "T" in g else "short".
Answer: it reports tall and short; test "T" in g instead.
Log in to join the discussion.
Loading…