23 lines
669 B
Python
23 lines
669 B
Python
import random
|
||
|
||
|
||
# 概率计算表明,23个人中有至少两人生日相同的概率高达50.7%,听起来有些反直觉,我们来通过计算估计这一概率。
|
||
def contains_same_birthday(birthdays):
|
||
# 修改代码,判断birthdays这个list中是否有相同的元素
|
||
return True
|
||
|
||
|
||
# 我们进行10000次测试
|
||
test_count = 10000
|
||
# 有至少两人生日相同的次数
|
||
true_count = 0
|
||
|
||
for i in range(test_count):
|
||
birth_days = []
|
||
for j in range(23):
|
||
birth_days.append(random.randint(1, 365))
|
||
|
||
# 统计满足条件的测试次数
|
||
|
||
# 输出测试结果,保留4位小数
|
||
print('23个人中有至少两人生日相同的概率是:')
|