• + 0 comments

    python3:

    p = 4/5
    n = 4
    
    
    def binom(k, n, p):
        res = 1
        a = 1
        for i in range(1, n+1):
            a *= i
        b = 1
        for i in range(1, n-k+1):
            b *= i
        c = 1
        for i in range(1, k+1):
            c *= i
        return a/b/c * p**k * (1-p)**(n-k)
    
    
    def prob(k):
        return binom(k, n, p)
    
    
    if __name__ == '__main__':
        result = prob(3) + prob(4)
        print('%.3f' % result)
    
        result = prob(0) + prob(1)
        print('%.3f' % result)