Sort by

recency

|

219 Discussions

|

  • + 0 comments
    from math import comb
    boy_ratio, girl_ratio = map(float, input().split(" "))
    pb = boy_ratio / (boy_ratio + girl_ratio)
    pf = 1 - pb
    print(round(sum(comb(6, x) * (pb**x) * (pf**(6 - x)) for x in range(3, 7)),3))
    
  • + 0 comments

    Plug x = 3, 4, 5 and 6 into the Binomial Distribution equation to find the proportion of families with 3, 4, 5 and 6 boys respectively and sum them up.

    import math
    boys = 1.09/2.09
    girls = 1/2.09
    ans = 0
    for x in range(3, 7):
        ans += math.comb(6, x)*boys**x*girls**(6-x)
    print(round(ans, 3))
    
  • + 0 comments
    import math
    # Read input from STDIN
    input_line = input()
    
    # Split the input into a list of values
    values = input_line.split()
    
    # Convert the values to the appropriate data types
    p = float(values[0])/(float(values[0])+float(values[1]))
    q = float(values[1])/(float(values[0])+float(values[1]))
    n = 6
    
    
    def binomial():
        result = 0
        for i in range(1,7):
            pdf = (math.factorial(n)/(math.factorial(i)*((math.factorial(n-i)))))*(p**i)*(q**(n-i))
            if i >= 3:
                result = result + pdf
                
        print(round(result, 3)) 
            
            
    binomial()
    
  • + 1 comment

    It says: No sample test-cases for this question. Please test your code against custom input.

    What to do with this?

  • + 0 comments
    b, g = map(float, input().split(' '))
    
    p= b/(b+g)
    
    def func(n):
        if n == 1 or n==0:
            return 1
        else:
            return n * func(n-1)
    
    def Binomial_Distribution(r, n, p):
        return func(n)/(func(r)*func(n-r))*(p**r)*((1-p)**(n-r))
    
    res = 0.0
    
    for i in range(3, 7):
        res+= Binomial_Distribution(i, 6, p)
    
    print(round(res, 3))