← Projects

Calculating pi using machin-like formula

be7ac08c7e59427d9f2631ee4a23be90328a3087 · Karan Goel · Jul 14, 2013 13:21

+5 −2 · 1 file changed

  • Numbers/pi.py +5 −2
diff --git a/Numbers/pi.py b/Numbers/pi.py
index 2aff429..5594801 100644
--- a/Numbers/pi.py
+++ b/Numbers/pi.py
@@ -1,7 +1,10 @@
 # Find PI to the Nth Digit
 
-import math
+from math import *
 
 digits = raw_input('Enter number of digits to round PI to: ')
 
-print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting
+# print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting
+
+# calculate pi using Machin-like Formula
+print ('{0:.%df}' % min(30, int(digits))).format(4 * (4 * atan(1.0/5.0) - atan(1.0/239.0)))