Created
July 28, 2020 14:58
-
-
Save CodeDrome/dc998a4afa63dcc9fe234f2e942fbdc1 to your computer and use it in GitHub Desktop.
estimatingpi.py part 1
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 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