A progress bar of pi (Π)! ! !

Selection calculated pi: pi / 4≈1-1 / 3 + 1 / 5-1 / 7 + ······ calculated pi (Π).

code show as below:

 1 import time
 2 import math
 3 print("------Begin------")
 4 start=time.perf_counter()    #开始计时
 5 scale=10
 6 for i in range(scale+1):
 7     a='*'*i
 8     b='.'*(scale-i)
 9     c=(i/scale)*100
10     print("{:^3.0f}%[{}->{}]".format (C, A, B))
 . 11      the time.sleep (0.5 )
 12 is      
13 is Sign. 1 =                      # calculates PI ([pi) /. 4 
14 PI = 0
 15 n-. 1 =
 16 A. 1 =
 . 17  the while (ABS (A)> 1E-. 6):         # range can change a change the precise value of 
18 is      PI + = a
 . 19      n-+ = 2
 20 is      Sign = - Sign
 21 is      a = Sign / n-
 22 is PI =. 4 * PI
 23 is  Print (PI)
 24  
25 End = Time. perf_counter ()     # timing end 
26  Print("{:.2f}s".format(end-start))     
27 print("------End------")
A progress bar of pi

Results are as follows:

 

Guess you like

Origin www.cnblogs.com/zhENie/p/12555997.html