某班级有n个人,(n<=365)问至少有两个人的生日在同一天的概率有多大?
由于如果使用公式的话365^300次方计算量很大,所以使用迭代的方式
for n in range(1, 366):
s = 1
for i in range(n):
s *= (365 - i) / 365
print(n, 1-s)
n=50 时 已经很大了
组合数的计算,默认使用小数,可以指定使用整数计算
from scipy.special import comb, perm
print(comb(10, 2))
print(comb(10, 2, exact=True))
print(perm(10, 2))
print(perm(10, 2, exact=True))
45.0
45
90.0
90
模拟计算,使用模拟数据和公式计算的对比,基本符合要求
from scipy import stats
def fun1(n):
"&#