import itertools as IT
hits = 0
for roll in IT.product(range(1,7), repeat=3):
if roll[0] > roll[1] + roll[2]:
hits += 1
print(roll, roll[1]+roll[2])
total = 6**3
print('Probability of first roll > sum of 2 rolls: {}/{} ~= {:.2%}'
.format(hits,total,hits/total))
由于可能性的总数很小,6**3,我们可以简单地列举所有可能性,并计算出我们感兴趣的事件数:
报告
^{pr2}$(根据Aniket Rangrej's solution更正)。在
相关问题 更多 >
编程相关推荐