Course 5.2Lesson 3 of 3
Real crosses are a matter of chance. random.choice picks one gamete from each parent, and a loop makes many offspring. For a few plants the share of short ones wanders far from 25 %; for thousands it settles near it. A bar chart compares observed with expected.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
A Punnett square says one in four plants of Tt with Tt is short. It does not say that every four plants hold exactly one short plant. Each seed is a separate chance event, like a coin toss.
Mendel saw this. His counts were close to 3:1, but never exactly 3:1. A computer can show why, by making thousands of crosses in a second.
random.choice picks one item from a string or list, each equally likely. A gamete is one letter chosen at random from a parent:
Each call gives a new child: sometimes TT, sometimes Tt, sometimes tt.
A generator inside Counter makes and counts many children at once:
The _ is a loop variable that is not used. With 100 plants you might see 23 short, or 29, or 21. Each run is different.
random.seed(3) at the top makes the "random" numbers start from the same place every run. Then you, a classmate and a teacher all see the same output, which makes checking easy. Remove the seed and each run differs.
With random.seed(3), the program at the end of this lesson prints:
The share jumps about for a few plants and settles near 25 % for many. This is the law of large numbers. It is why Mendel counted hundreds of plants, not a handful.
How far does a count usually wander? For plants with a chance of being short, the typical wander is plants. It grows with , but slower than , so the share wanders less and less.
A bar chart puts the two side by side. The expected counts come from the ratio: for plants, tall and short.
Shifting the second set of bars by puts each pair side by side. When the bars are close, the data agree with the 3:1 rule.
The program crosses Tt with Tt for 20, 100, 1000 and 10000 plants with a fixed seed. It prints the share of short plants each time, then draws observed against expected for the last run.
random.choice(mum) + random.choice(mum) is a cross of mum with herself, not with dad.random.choice(parent) picks one gamete; 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 on every run.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
random.seed(3) change, and what does it not change?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…