Created
November 14, 2014 16:45
-
-
Save benawad/234b7e2b1f976a9f9118 to your computer and use it in GitHub Desktop.
solution#1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from decimal import * | |
print "Enter a number and I will print out that many decimal places of PI." | |
places = int(raw_input('>')) | |
getcontext().prec = places | |
pi = 0 | |
for k in range(places): | |
pi += Decimal(16**-k) * ( Decimal(4/(8*k + 1)) - Decimal(2/(8*k + 4)) - Decimal(1/(8*k + 5)) - Decimal(1/(8*k + 6)) ) | |
print "Here is" , places , "decimal places of PI:" , pi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment