Mohammad Abedi Mohammad Abedi - 2 years ago 287
Python Question

Binomial Distribution probability in python

for this problem:

The ratio of boys to girls for babies born in Russia is 1.09:1 If there is one child born per birth, what proportion of Russian families with exactly 6 children will have at least 3 boys?
Write a program to compute the answer using the above parameters:
A single line containing the following values:

1.09 1

this is my program:

p1=float(pp[:pp.find(' ')])
p2=float(pp[pp.find(' ')+1:])
from math import factorial as f
def comb(n,r):
return f(n) / f(r) / f(n-r)
for i1 in range(1,7):
if i1>=3:

the answer Ive got is 0.688 where the correct answer is 0.696, whats the problem in my code?

Answer Source

You need to calculate the probability:

from math import factorial as f
b, g = map(float, input().split())
p = b / (b+g)
def comb(n, r):
    return f(n) / (f(r) * f(n-r))
n = 6
sum(p**k * (1-p)**(n-k) * comb(n, k) for k in range(3, 7))
# 0.6957033161509107
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download