1#import pi function from math module
2from math import pi
3
4#Show pi value
5print(pi)
1# Approximation of the number PI through the Nilakantha's series
2
3from decimal import *
4getcontext().prec = 100
5
6s = Decimal(1); #Signal for the next operation
7pi = Decimal(3);
8
9n = input("Enter the number of iterations: ")
10
11for i in range (2, n * 2, 2):
12 pi += (s*(Decimal(4)/(Decimal(i)*(Decimal(i)+Decimal(1))*(Decimal(i)+Decimal(2)))))
13 s *= -1
14
15print ("Aproximated value of PI :")
16print (pi)
1import math #importing the math functions
2
3pi = math.pi #getting the value of pi
4
5print(pi) #printing the result