Calculating pi using machin-like formula
+5 −2 · 1 file changed
-
Numbers/pi.py+5 −2
@@ -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)))