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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started