I am trying to solve a study problem with Pi in Python. The task is to print N-decimal numbers of Pi. When using the decimal library, everything goes smoothly, but we cannot use that :( At this moment I can only return 15 decimals. Please, can you explain to me why it stops at 15 and how to return more then 15? Many thanks.
def calc_pi(n):
pi = 0
k = 0
for k in range(n):
pi += (16**(-k)) * ((4/(8*k + 1)) - (2/(8*k + 4)) - (1/(8*k + 5)) - (1/(8*k + 6)))
return str(pi)
print(calc_pi(100))
>>> 3.141592653589793