Skip to content

Instantly share code, notes, and snippets.

@unacceptable
Created September 16, 2025 16:13
Show Gist options
  • Select an option

  • Save unacceptable/36ed3420c8ecbf257414771a507c81f7 to your computer and use it in GitHub Desktop.

Select an option

Save unacceptable/36ed3420c8ecbf257414771a507c81f7 to your computer and use it in GitHub Desktop.
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