Answer to Question #266029 in Python for Sam

Question #266029

You can approximate n by using the following summation:


n=4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ..... + (-1)i + 1/2i - 1





Write a program that displays the n value for i = 10000, 20000, … and 100000.



Program Output:


3.1414926535900345


3.1415426535898248


3.141559320256462


3.1415676535897985


3.1415726535897814


3.141575986923102


3.141578367875482


3.1415801535897496


3.1415815424786238


3.1415826535897198

1
Expert's answer
2021-11-15T00:20:22-0500

#function for finding the approximate number

def pi_approx(n):

#adding number to n variable  

   

  return 4*sum([((-1)**i)/(2*i+1) for i in range(10000)])


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS