1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
from itertools import combinations
PROBABILITIES = {
('AA', 'AA'): 1.00,
('AA', 'Aa'): 1.00,
('AA', 'aa'): 1.00,
('Aa', 'Aa'): 0.75,
('Aa', 'aa'): 0.50,
('aa', 'aa'): 0.00
}
def mendel_inheritance(k, m, n) -> float:
pool = ['AA'] * k + ['Aa'] * m + ['aa'] * n
matings = tuple(combinations(pool, 2))
total_probability = sum(PROBABILITIES[mating] for mating in matings)
average_probability = total_probability / len(matings)
return round(average_probability, 5)
|