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