Created
October 13, 2018 03:14
-
-
Save chand1012/1b00aa83fc422856ff1dc99e66aff01a to your computer and use it in GitHub Desktop.
Catalan's constant calculator in python
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
# Simple Catalan's Constant implimentation in python | |
# Written for some homework, hope someone else finds it useful | |
# n being the times the number is calculated, increasing n increases accuracy | |
from fractions import Fraction | |
n = int(raw_input("enter N:")) | |
k = 1 | |
sum = 0 | |
sign = 1 | |
while True: | |
if k<=n: | |
top = ((-1)**(k-1)) | |
bottom = (((2*k)+1)**2) | |
frac = Fraction(top, bottom) | |
sum += frac | |
k+=1 | |
else: | |
break | |
print(float(sum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment