Skip to content

Instantly share code, notes, and snippets.

@benawad
Created November 14, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benawad/234b7e2b1f976a9f9118 to your computer and use it in GitHub Desktop.
Save benawad/234b7e2b1f976a9f9118 to your computer and use it in GitHub Desktop.
solution#1.1
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