Skip to content

Commit be7ac08

Browse files
author
Karan Goel
committed
Calculating pi using machin-like formula
1 parent 9954281 commit be7ac08

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Numbers/pi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Find PI to the Nth Digit
22

3-
import math
3+
from math import *
44

55
digits = raw_input('Enter number of digits to round PI to: ')
66

7-
print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting
7+
# print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting
8+
9+
# calculate pi using Machin-like Formula
10+
print ('{0:.%df}' % min(30, int(digits))).format(4 * (4 * atan(1.0/5.0) - atan(1.0/239.0)))

0 commit comments

Comments
 (0)