Spaces:
Sleeping
Sleeping
| import random | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| pi_facts = [ | |
| "π is irrational and never ends!", | |
| "π has been calculated to over 62 trillion digits!", | |
| "The symbol π was first used in 1706.", | |
| "You can’t express π as a fraction!", | |
| "March 14 (3/14) is Pi Day!" | |
| ] | |
| def random_pi_fact(): | |
| return random.choice(pi_facts) | |
| def generate_pi_graph(): | |
| digits = [int(d) for d in open('pi_digits.txt').read() if d.isdigit()] | |
| x = list(range(len(digits))) | |
| y = np.cumsum([(-1)**i * d for i, d in enumerate(digits[:500])]) | |
| fig, ax = plt.subplots() | |
| ax.plot(x[:len(y)], y) | |
| ax.set_title("π Waveform based on Digits") | |
| return fig | |