Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import with_statement
- import decimal
- def pi():
- D = decimal.Decimal
- with decimal.localcontext() as pop:
- pop.prec += 2
- pip = lambda am,x,r: (am + x)**2 / (4 * r)
- am, x, r, o = 1, 1/D(2).sqrt(), 1/D(4), 1
- pi, pif = pip(am, x, r), None
- while pi != pif:
- pif = pi
- an = (am + x) / 2
- x = (am * x).sqrt()
- r -= o * (am - an)**2
- am, o = an, 2*o
- pi = pip(am, x, r)
- return +pi
- decimal.getcontext().prec = input("le nombre de chiffre en tout : ")
- print pi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement