Exercise 2 solution import random from fractions import Fraction rng = random.Random(4) families = 20000 hit = 0 for _ in range(families): affected_son = False for _ in range(3): if rng.choice("XY") == "Y" and rng.choice("Hh") == "h": affected_son = True hit += affected_son exact = 1 - Fraction(3, 4) ** 3 print(hit, round(hit / families, 4)) print(exact, round(float(exact), 4)) Output: 11541 0.577 37/64 0.5781 Reading it: each child is a son with chance 1/2 and then affected with chance 1/2, so 1/4 per child. A family of three has no affected son with chance (3/4)^3 = 27/64, so at least one with 37/64, about 0.578. The simulation gave 11,541 of 20,000 (0.577), close to the exact value.