Write a well-documented Python program that determines the number of terms in th
ID: 3745377 • Letter: W
Question
Write a well-documented Python program that determines the number of terms in the infinite series of Nilakantha, Leibnitz and Adamchick to obtain a specified level of precision with the actual value of , as computed by Python's math module. Your program prompts a user for an integer M. Your application identifies the number of terms N to achieve an estimate of within 10-M Submit your solution in a Python text file whilemypi.py, using the functions developed for the series in Question 1 Hints: Your program code should import math as m. Using a while loop, continue to evaluate the series until it is within the tolerance of 10-M of Python's . Use the absolute value function in your evaluation Next Steps (not graded, not to be handed in): Embed your solution into a for-loop that iterates N from 1/1,000 to 1/1,000,000,000,000 in powers of ten to determine the level of precision. Suppress your answer for Leibnitz Series to avoid long computational times Number of Terms Required To Compute 10 Ism nsm aw 10 10 10Explanation / Answer
from math import pi
from decimal import Decimal, getcontext
def Nilakantha(limit,error):
n,PI,i,sign=1,3,2,1
while abs(limit-PI) > error :
temp=Decimal(4)/Decimal(i*(i+1)*(i+2))
n+=1
i+=2
PI+=sign*temp
sign=-sign
return n
def Leibniz(limit,error):
n,PI,i,sign=1,0,1,1
while abs(limit-PI) > error :
temp=Decimal(4)/Decimal(i)
n+=1
i+=2
PI+=sign*temp
sign=-sign
print(PI,end=' ')
return n
def Adamchick(limit,error):
n,PI=0,0
while abs(limit-PI) > error :
temp=1/Decimal(16)**n * (Decimal(4)/(8*n+1) - Decimal(2)/(8*n+4) - Decimal(1)/(8*n+5) - Decimal(1)/(8*n+6))
n+=1
PI+=temp
print(PI,end=' ')
return n
M=int(input('Digits of Precision: '))
getcontext().prec = M //To set precision
Pi=Decimal(pi)/Decimal(1)
print(Adamchick(Pi,10**(-1*M))) //second argument is the error limit
print(Nilakantha(Pi,10**(-1*M)))
print(Leibniz(Pi,10**(-1*M)))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.