Python Demo 02 蒙特卡罗方法输出e
生活随笔
收集整理的這篇文章主要介紹了
Python Demo 02 蒙特卡罗方法输出e
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過蒙特卡羅方法對e進行計算:
from random import* # 蒙特卡羅方法求解e DARTS = 1024*1024 count = 0 for i in range(DARTS):# 在此面積內隨機分布點,x = uniform(1,2)y = uniform(0,1)if x*y >1:count += 1 e = pow(2, DARTS/count) #根據ln2反算e,ln2=loge2 print("{}".format(e))?
總結
以上是生活随笔為你收集整理的Python Demo 02 蒙特卡罗方法输出e的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python Demo 01 爬取大学
- 下一篇: Python Demo 03 星期输出