Created
September 16, 2025 16:13
-
-
Save unacceptable/36ed3420c8ecbf257414771a507c81f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def pi(n_terms: int) -> float: | |
| ''' | |
| Approximate pi using the Leibniz formula | |
| ''' | |
| series = [ | |
| (-1)**k / (2*k + 1) for k in range(n_terms) | |
| ] | |
| pi_approx = 4*( | |
| sum(series) | |
| ) | |
| print("Last number in series: ", int(1/series[-1])) | |
| return pi_approx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment