Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. from decimal import Decimal, getcontext
  2.  
  3. precision = int(input('Enter the precision: ')) + 1
  4. if not (precision - 1):
  5.     pi = 3
  6. else:
  7.     getcontext().prec = precision
  8.     pi = sum([(1/Decimal(16)**k * (Decimal(4)/(8*k+1) - Decimal(2)/(8*k+4) - Decimal(1)/(8*k+5) - Decimal(1)/(8*k+6))) for k in range(precision)])
  9. print(pi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement