Answer to Question #268904 in Python for Pere

Question #268904


You can approximate pi by using the following summation: pi=4(1−1/3+1/5−1/7+1/9−1/11+⋯+(−1)^i+1/2i-1)

Write a program that displays the pi 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-19T14:38:52-0500
n = 10000
for i in range(1, 11):
   s = 0
   for i in range(1, n):
      s += ((-1) ** (i + 1)) / (2 * i - 1)
   print(f'i = {n} pi =', 4 * s)
   n += 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