A health worker wants to see how close real counts come to one half. You will write a function that gives the child for a sperm, simulate many births, and find the fraction of girls. The program then draws a bar chart.
The idea. The egg always carries an X. A sperm carries X or Y with equal chances. X with X gives a girl; X with Y gives a boy.
Your tasks.
child, return "girl" if sperm is "X", and "boy" if it is "Y".children to the list of children for every sperm in sperms, in order.girls to the number of girls in children.fraction to the fraction of girls, rounded to two decimal places.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…