Advertisement
jukaukor

Pi_decimals.py

Mar 14th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # Decimal's of Pi using Bailey-Borwein-Plouffe formula
  2. # Juhani Kaukoranta, @jukaukor , on Pi's day 2018-03-14
  3.  
  4. from decimal import *
  5. def pii(precision):
  6. getcontext().prec=precision
  7. s = Decimal(0)
  8. for k in range(0,precision):
  9. s = s + 1/Decimal(16)**k*(
  10. Decimal(4)/(8*k+1) -
  11. Decimal(2)/(8*k+4) -
  12. Decimal(1)/(8*k+5) -
  13. Decimal(1)/(8*k+6))
  14. return s
  15.  
  16. pidecimals = int(input("How many digits you want for Pi's value? "))
  17. Pi_value = pii(pidecimals+1)
  18. print ("Value of Pi with ",pidecimals," digit precision: ")
  19. print(Pi_value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement