Skip to content

Instantly share code, notes, and snippets.

@Basicprogrammer10
Last active Nov 7, 2021
Embed
What would you like to do?
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