您的位置:首页 > 其它

黑白球/古典概率的计算

2017-10-13 01:17 393 查看
import random
def test(n,T):
count = 0
count1 = 0
while count1 < T:
a = [0,0,0,0,1,1]
b = [0,0,0,1,1,1,1]
if int(n) <= len(a):
list1 = random.sample(a,n)
for i in list1:
a.remove(i)
list2 = random.sample(b,n)
for i1 in list2:
b.remove(i1)
b.append(i)
a.append(i1)
count1 += 1
if a.count(0) == 4:
count += 1
print '%.2f'% (count*1.0/T)
n=input()
T=100000
test(n,100000)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: