Please Login in order to post a comment
TĐH p=4/5 from math import comb
n=4 k1=3 k2=4 print(round(comb(n,k1)*pow(p,k1)*pow(1-p,n-k1)+comb(n,k2)*pow(p,k2)*pow(1-p,n-k2)),3) n=4 k1=1 k2=0 print(round(comb(n,k1)*pow(p,k1)*pow(1-p,n-k1)+comb(n,k2)*pow(p,k2)*pow(1-p,n-k2),3))
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)
from math import factorial as fact
def permutation(n, r): return fact(n)/(fact(n-r))
def combination(n, r): return permutation(n,r)/fact(r)
def binomial_dist(n, x, p):
q = 1-p
return combination(n, x)*(p**x)(q*(n-x))
The rest you can do :)
Also make sure to put the zero
AAARGH you really need to round the answers in the solution checker, not just compare the files.
If you're solving this problem, you should ONLY output 3 decimals. The instructions are not clear.
No more comments
Seems like cookies are disabled on this browser, please enable them to open this website
TĐH p=4/5 from math import comb
P(X>2)=P(X=3)+P(X=4)=kCn*p(k)*(1-p)^(n-k)
n=4 k1=3 k2=4 print(round(comb(n,k1)*pow(p,k1)*pow(1-p,n-k1)+comb(n,k2)*pow(p,k2)*pow(1-p,n-k2)),3) n=4 k1=1 k2=0 print(round(comb(n,k1)*pow(p,k1)*pow(1-p,n-k1)+comb(n,k2)*pow(p,k2)*pow(1-p,n-k2),3))
python3:
from math import factorial as fact
Permutation
def permutation(n, r): return fact(n)/(fact(n-r))
Combinations
def combination(n, r): return permutation(n,r)/fact(r)
BINOMIAL DISTRIBUTION
def binomial_dist(n, x, p):
q = 1-p
return combination(n, x)*(p**x)(q*(n-x))
The rest you can do :)
Also make sure to put the zero
AAARGH you really need to round the answers in the solution checker, not just compare the files.
If you're solving this problem, you should ONLY output 3 decimals. The instructions are not clear.