Honors 270 Assignment 3

Directions

Calculating pi

Use the formula:

` π = 4 ( 1 - 1/3 + 1/5 - 1/7 + ... ) `

Write a python program that uses a while loop to do this calculation.

Initially, have your code run through the while loop for 5 terms of this series, and print out the sum after each term.

Then have your program use an if statement to print out the approximation for π every time mth term of the series, where m is a value that you set in your program. Also have your program set so that it runs through n terms of the series, where n is another value set in the code.

1. Initially run your program with m=20 and n=1000. Attach results from this run to your assignment.

2. How accurate is this method of approximating π? How many terms in the series do you need to get pi right to 2 decimal places?

3. Now rerun your program with m=200 and n=10000.

How many decimal places is this run good too?

4. Test the limits of the accuracy of your code. Can you get it to find π to 8 decimal places? to 10 decimal places? to the 11 decimal places python shows by default? Or does it stop getting more precise at some point? (Feel free to stop trying once it takes more than 5 minutes for your code to run. If you stop due to time, make a note of the number of terms that you stop at.)

For reference, to 100 decimal places π = 3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679

You won't be able to get nearly that many decimal places.