Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created April 15, 2024 13:38
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 CodeDrome/a283d17ed3c1c4a74fd42e1dab5e02f4 to your computer and use it in GitHub Desktop.
Save CodeDrome/a283d17ed3c1c4a74fd42e1dab5e02f4 to your computer and use it in GitHub Desktop.
estimatingpi.py part 1
import math
PI_STRING = "3.141592653589793238"
RED = "\x1B[31m"
GREEN = "\x1B[32m"
RESET = "\x1B[0m"
def main():
"""
Here we simply call the functions which estimate pi using various methods
"""
print("-----------------")
print("| codedrome.com |")
print("| Estimating Pi |")
print("-----------------\n")
#fractions()
#francois_viete()
#john_wallis()
#john_machin()
#gregory_leibniz()
#nilakantha()
def print_as_text(pi):
"""
Takes a value for pi and prints it below a definitive value,
with matching digits in green and non-matching digits in red
"""
pi_string = str("%1.18f" % pi)
print("Definitive: " + PI_STRING)
print("Estimated: ", end="")
for i in range(0, len(pi_string)):
if pi_string[i] == PI_STRING[i]:
print(GREEN + pi_string[i] + RESET, end="")
else:
print(RED + pi_string[i] + RESET, end="")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment