first commit
This commit is contained in:
parent
abc6526143
commit
26631f9b48
24 changed files with 1089 additions and 1 deletions
23
Exercise/exercise-5.2.py
Normal file
23
Exercise/exercise-5.2.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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个人中有至少两人生日相同的概率是:')
|
||||
Loading…
Add table
Add a link
Reference in a new issue