首页 > 其他 > 详细

[刷题] 统计首位数

时间:2020-01-30 00:03:02      阅读:105      评论:0      收藏:0      [点我收藏+]

练习1:统计从1到100的阶乘中,1到9做首位的次数

Python

import matplotlib.pyplot as plt
def first_digital(x):
    while x >= 10:
        x //= 10
    return x
if __name__ == __main__:
    n = 1
    frequency = [0]*9
    for i in range(1,100):
        n *= i
        m = first_digital(n)-1
        frequency[m] += 1

print(frequency)
plt.plot(frequency,r-,linewidth=2)
plt.grid(True)
plt.show()

本福特定律(第一数字定律):以1为首位数字出现的概率约30%,是直观想象1/9的三倍

 

[刷题] 统计首位数

原文:https://www.cnblogs.com/cxc1357/p/10367548.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!