how to import math in python
import math
pi python
# Approximation of the number PI through the Nilakantha's series
from decimal import *
getcontext().prec = 100
s = Decimal(1); #Signal for the next operation
pi = Decimal(3);
n = input("Enter the number of iterations: ")
for i in range (2, n * 2, 2):
pi += (s*(Decimal(4)/(Decimal(i)*(Decimal(i)+Decimal(1))*(Decimal(i)+Decimal(2)))))
s *= -1
print ("Aproximated value of PI :")
print (pi)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us