Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > 其他编程语言 > 计算PI的Python程序
【标  题】:计算PI的Python程序
【关键字】:PI,Python
【来  源】:http://www.cublog.cn/u/8780/showart.php?id=271076

计算PI的Python程序

Your Ad Here

import sys

def main():
    k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
    while 1:
        # Next approximation
        p, q, k = k*k, 2L*k+1L, k+1L
        a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
        # Print common digits
        d, d1 = a/b, a1/b1
        while d == d1:
            output(d)
            a, a1 = 10L*(a%b), 10L*(a1%b1)
            d, d1 = a/b, a1/b1

def output(d):
    # Use write() to avoid spaces between the digits
    # Use str() to avoid the 'L'
    sys.stdout.write(str(d))
    # Flush so the output is seen immediately
    sys.stdout.flush()

if __name__ == "__main__":
    main()

Python 绝对简明手册:【上一篇】
Adapter:【下一篇】
【相关文章】
  • Python 绝对简明手册
  • Python 各种方面的技巧片段
  • Python的3元运算
  • Python Cookbook 第二版 汉化版 [Recipe 1.8] 检测字符串是否包含特定的字符集合
  • Windows API 函数学习(14)---SN填写代码
  • Finally, I resolved the python-devel dependence issue
  • 用python写的一个网页测试工具
  • 用"C原生API"写Symbian日志文件
  • Fahrenheit 图形API
  • Direct3D学习(一):3D Sierpinski镂垫绘制
  • 【随机文章】
  • 我快疯了? 不知道是怎么回事如果大侠看到我的回帖指点一二多谢
  • Java集合框架(转)
  • LOTUS 程序精选
  • 桌面型视频会议终端RP VC-3000
  • linux系统主机安全配置!
  • 修改Atheros芯片的无线网卡为任意品牌网卡
  • flash组件+PHP+MYSQL的新闻发布系统
  • 用wget做网站的本地镜像
  • 项目开发的工具cvsnt(转)
  • Windows Live介绍
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.