Sort by

recency

|

157 Discussions

|

  • + 0 comments
    from math import comb
    n = 10
    p = 0.12
    print(round(sum(comb(n, i) * (p**i) * ((1 - p)**(n - i)) for i in range(3)),3))
    print(round(1 - sum(comb(n, i) * (p**i) * ((1 - p)**(n - i)) for i in range(0, 2)),3))
    
  • + 1 comment
    #python
    import math
    p=0.12
    q=1-p
    case1=0
    case2=0
    for x in range(0, 3):
        case1+=math.comb(10, x)* (p**x)*(q**(10-x))
    for x in range(2, 11):
        case2+=math.comb(10, x)* (p**x)*(q**(10-x))
    print(round(case1, 3), round(case2, 3), sep='\n')
    
  • + 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 = int(values[0])/100
    q = (1-p)
    n = int(values[1])
    
    def binomial():
        resultOne = 0
        resultTwo = 0
        
        for i in range(0,3):
            pdf = (math.factorial(n)/(math.factorial(i)*((math.factorial(n-i)))))*(p**i)*(q**(n-i))
            if i <= 2 :
                resultOne = resultOne + pdf
    
        for i in range(1,(n+1)):
            pdf = (math.factorial(n)/(math.factorial(i)*((math.factorial(n-i)))))*(p**i)*(q**(n-i))     
            if i >= 2:
                resultTwo = resultTwo + pdf    
        
        print(round(resultOne, 3))
        print(round(resultTwo, 3))     
        
    
    binomial()
    
  • [deleted]
    + 0 comments

    Python 3 code:

    def fact(n):
        return 1 if n == 0 else n*fact(n-1)
    
    def comb(n, x):
        return fact(n) // (fact(x) * fact(n-x))
    
    def binomial(x, n, p):
        return comb(n, x) * p**x * (1-p)**(n-x)
    
    p, n = list(map(int, input().split(" ")))
    print(round(sum([binomial(i, n, p/100) for i in range(3)]), 3))
    print(round(sum([binomial(i, n, p/100) for i in range(2, n+1)]), 3))
    
  • + 0 comments
    from math import comb as c
    n, p, q = 10, 0.12, 0.88
    print(f'{sum(map(lambda x:c(n,x)*p**x*q**(n-x),range(0,3))):.3f}')
    print(f'{sum(map(lambda x:c(n,x)*p**x*q**(n-x),range(2,11))):.3f}')