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
from datetime import datetime | |
import decimal | |
file = open('Pi.txt', 'w') | |
file.write("Pi Finder V2\n") | |
file.write("Made By Connor Slade\n") | |
def pi(): | |
decimal.getcontext().prec += 2 | |
three = decimal.Decimal(3) | |
lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24 | |
while s != lasts: | |
lasts = s | |
n, na = n + na, na + 8 | |
d, da = d + da, da + 32 | |
t = (t * n) / d | |
s += t | |
decimal.getcontext().prec -= 2 | |
return +s | |
x = int(input("precision: ")) | |
file.write("Precision: " + str(x) + "\n") | |
file.write("-------------------------\n") | |
decimal.getcontext().prec = x | |
pi = pi() | |
file.write(str(pi) + "\n") | |
file.write("-------------------------\n") | |
file.write("Finished at " + str(datetime.now())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment