Sort by

recency

|

158 Discussions

|

  • + 0 comments
    def fac(num):
        if num == 1 or num == 0:
            return 1
        else:
            return num * fac(num - 1)
    
    s, t = 0, 0
    pcn, n = map(int, input().split())
    p =pcn / 100  
    
    for i in range(0, 3):
        t += (fac(n) / (fac(n - i) * fac(i))) * (p ** i) * ((1 - p) ** (n - i))
    print(round(t, 3))
    
    for i in range(2, n + 1):
        s += (fac(n) / (fac(n - i) * fac(i))) * (p ** i) * ((1 - p) ** (n - i))
    print(round(s, 3))
    
  • + 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))