Python入门习题5.蒙特卡罗方法计算圆周率
2024-08-29 23:48:58
#CalPi.py
from random import random
from math import sqrt
from time import clock
DARTS = 10000000
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.0 * (hits/DARTS)
print("pi值是{}".format(pi))
print("运行时间是:{:5.5}s".format(clock()))
最新文章
- CrashMonkey4IOS App测试
- 媒体查询使用方法@media
- [QDB] 幽灵分享:QDataSet+TQMSSQLConverter 实战技巧
- mysql之旅【第一篇】
- Delphi ActiveX Form的使用实例
- CnPlugin 1.5.400
- Cross Site Request Forgery (CSRF)--spring security -转
- css3图片滤镜
- 在fragment中获取他附着的activity中的变量
- POJ 2392 Space Elevator 背包题解
- 继承Object和ContextBoundObject处理效率上的差距
- 【Maven】运行项目,报ClassNotFound错误
- 树莓派安装ftp服务器
- 编译搭建Lamp服务器
- javascript里的几种常见的数组方法
- 开发环境中Docker的使用
- virualbox 虚拟机管理
- python random 随机选择操作
- 使用putty进行ssh tunnel远程内网机器
- TestNG+Excel+(HTTP+JSON) 简单接口测试
热门文章
- 启动ZOOKEEPER之后能查看到进程存在但是查不到状态,是因为。。。
- 点击按钮时,显示不同的div内容
- ElasticSearch基本概念阐述
- 实验查看PHP本地的Session信息
- TCP窗口
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number (莫队)
- 2019hdu多校3 hdu4893(线段树单点 区间更新
- [POI2007]POW-The Flood(并查集)
- JS大文件上传解决方案
- 特权第一讲--Lesson 1 课程概述与如何学好FPGA