Question: I'm trying to write this code that uses three different ways to calculate pi. So far I have the Nilakantha method accounted for and I

I'm trying to write this code that uses three different ways to calculate pi. So far I have the Nilakantha method accounted for and I can use any two others. The program is supposed to calculate pi for each type of function (Nilakantha, etc) to 10^-3 precision and rank which method took the least amount of iterations from high to low. Here is the code I have for that.

def nilakantha():

M=3 pi=3.1415926535897932384626433832795028841971 n=0 myPiBy4=3/4 #While will continue to iterate until the condition of precision of 10^-3 is false while (abs(4*myPiBy4-pi)>(10**(-M))): myPiBy4+=((-1)**n)/((2*n+3)**3-(2*n+3)) n+=1 return(n-1)

#Function needed for exam def main(): N=nilakantha() D={N:'myPiTwo'} #,A:'myPiOne'} for key,value in sorted (D.items()): print(value) main()

For this code, it takes python 5 iterations to get within 10^-3 precision. Can someone help me get the adamchik series in there? Whenever I try to do it the program doesn't work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!