Exercise 1 solution from itertools import product from fractions import Fraction def dominant_fraction(n): gam = list(product("Aa", repeat=n)) total = 0 hits = 0 for g1 in gam: for g2 in gam: total += 1 if all("A" in (x, y) for x, y in zip(g1, g2)): hits += 1 return hits, total for n in (1, 2, 3): h, t = dominant_fraction(n) print(n, h, t, Fraction(h, t), Fraction(3, 4) ** n == Fraction(h, t)) Output: 1 3 4 3/4 True 2 9 16 9/16 True 3 27 64 27/64 True Reading it: every gamete of an all-heterozygous parent is a choice of A or a for each gene. A child shows the dominant form of every gene only if at least one of its two gametes carries A at each position, and counting those cases gives (3/4) to the power n.