1.蒙特卡洛求圆周率 向区域内随即撒点 当点的数目足够多时,落在圆的点数目与在正方形点数目成正比 即圆的面积和正方形的面积成正比 可以得出计算圆周率的算法 DARTS=100000000 hits=0.0 clock() for i in range(1,DARTS+1): x,y=random(),random() dist=sqrt(x**2+y**2) if dist <=1.0: hits=hits+1 pi=4*(…
import math import time scale=30 s,m,=1,2 total,s,n,t=0.0,1,1.0,1.0 print("执行开始".center(scale//2, "-")) start = time.perf_counter() for i in range(scale+1): total+=t n+=2 s=-s t=s/n k=total*4 a = '*' * i b = '.' * (scale - i) c = (i/sc…