Advertisement
here2share

# b_pi.py

Sep 23rd, 2021
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # b_pi.py
  2.  
  3. def pi(places=20000):
  4.     "Computes pi to given number of decimal places"
  5.     extra = 8
  6.     one = 10 ** (places+extra)
  7.     t, c, n, na, d, da, i = 3*one, 3*one, 1, 0, 0, 24, 0
  8.     while 1:
  9.         n, na, d, da  = n+na, na+8, d+da, da+32
  10.         t = t * n // d
  11.         c += t
  12.         s = str(c // (10 ** extra))
  13.         try:
  14.             print s[i],
  15.         except:
  16.             break
  17.         i += 1
  18.    
  19. pi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement