2020
11-11
11-11
如何通过python计算圆周率PI
代码如下defPI(n):pi=0forkinrange(n):pi+=1/pow(16,k)*(4/(8*k+1)-2/(8*k+4)-1/(8*k+5)-1/(8*k+6))returnpiimporttimescale=20print("执行开始".center(scale+4,'-'))foriinrange(scale+1):a='*'*ib='.'*(scale-i)c=(i/scale)*100pi=PI(1000)print("{:^3.0f}%[{}->{}]".format(c,a,b))time.sleep(0.1)print("圆周率值是:{}".format(pi))print("执行结束".center(scale+4,'-'))结果如下...
继续阅读 >