zoukankan      html  css  js  c++  java
  • 带进度条的圆周率计算

     1 from tqdm import tqdm
     2 import time
     3 from random import random
     4 from math import sqrt
     5 DARTS=100000000
     6 hits=0.0
     7 time.clock()
     8 for i in range(1,DARTS):
     9     x,y=random(),random()
    10     dist=sqrt(x**2+y**2)
    11     if dist<=1.0:
    12         hits=hits+1
    13 for i in tqdm(range(1,DARTS//100000+1)):
    14     time.sleep(0.05)
    15 pi=4*(hits/DARTS)
    16 print("Pi值是{}.".format(pi))
    17 print("运行时间是:{:.5f}s".format(time.clock()))

  • 相关阅读:
    元组类型
    字符串类型
    列表类型
    python 循环
    python语句
    python运算符
    python1
    软件管理
    rpm yum
    LVM
  • 原文地址:https://www.cnblogs.com/litchi666/p/12600779.html
Copyright © 2011-2022 走看看