Created
March 15, 2016 12:26
-
-
Save mandyRae/1b9bac427815a065d920 to your computer and use it in GitHub Desktop.
Happy Pi Day!!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
j = 0 | |
pi = 0 | |
plusminus = True | |
start_time = time.time() | |
while True: | |
if j%2 == 1: | |
if plusminus == True: | |
pi += (1/j) | |
else: | |
pi -= (1/j) | |
plusminus = not plusminus | |
j += 1 | |
if j%1000000 == 0: | |
print('Time Elapsed:', time.time()-start_time) | |
if j%100000 ==0: | |
print('# of terms:',j) | |
print(pi*4) | |
#took approx 37,500,000 terms to reach pi to 8 sigfigs or 3.1415926 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment