Mohammad Abedi - 2 months ago 43

Python Question

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:

`pp=str(input())`

p1=float(pp[:pp.find(' ')])

p2=float(pp[pp.find(' ')+1:])

pf=0.0

pa=0.0

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:

pf=pf+(pow(p1,i1)+pow(p2,6-i1))*comb(6,i1)

pa=pa+(pow(p1,i1)+pow(p2,6-i1))*comb(6,i1)

print("%.3f"%(pf/pa))

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

Answer

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
```