Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Modified Ramanujan's formula of sqrt(2)/pi
- # Ramanujan wrote in 1914 his original formula of 1/pi
- # Juhani Kaukoranta 18.6.2018
- from decimal import *
- import math
- def RamanujanInversePi(precision):
- getcontext().prec=precision
- inverse = Decimal(0)
- for n in range(0,precision):
- inverse = inverse + Decimal(1)*math.factorial(4*n)/(math.factorial(n))**4*(26390*n+1103)/396**(4*n)
- inverse = inverse*4/9801
- return(inverse)
- numbers = int(input("Kuinka monta numeroa haluat "))
- inversePi = RamanujanInversePi(numbers)
- print("sqrt(2)/pi = ",inversePi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement