Skip to content

Instantly share code, notes, and snippets.

@jugmac00
Created May 13, 2021 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugmac00/85755d4326fe6cd2aa481923c78884ca to your computer and use it in GitHub Desktop.
Save jugmac00/85755d4326fe6cd2aa481923c78884ca to your computer and use it in GitHub Desktop.
# pi_approx.py
from math import pi
def approximate_pi(iteration_count: int) -> float:
sign, result = 1, 0.0
for at in range(iteration_count):
result += sign / (2 * at + 1)
sign *= -1
return result * 4
if __name__ == "__main__":
approx_1, approx_2 = approximate_pi(300), approximate_pi(301)
print(f"approx 300 {approx_1} with diff {approx_1 - pi}")
print(f"approx 301 {approx_2} with diff {approx_2 - pi}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment