Ans:
Initially calculate the factorial of n:
def fact(n):
if n == 0:
return 1
else:
factorial = fact(n-1)
ans = n * factorial
return ans
Then calculate the value for pi using the below function:
def pi_value():
total = 0
i= 0
first_term = 2 * math.sqrt(2) / 9801
start = True
while start == True:
numerator = float(fact(4*i) * (1103 + 26390 * i))
denominator = float(fact(i)**4) * 396**(4*i)
final_term = first_term * float(numerator/denominator)
total =total+ final_term
i =i + 1
if final_term < 1e-15:
start == False
print("The value of pi is:" )
break
return 1 / total
print(pi_value())
------------------------------------------------------------------------------------------------------------------------------------------------------------
Output
![import math Window Help Python 3.6.5 (v3.6.5:f59c0932b 4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win3 def fact](http://img.homeworklib.com/questions/94b1b1f0-7489-11eb-990e-3935f477f289.png?x-oss-process=image/resize,w_560)
Using Java's Biglnteger / BigDouble import java.math), Python, solve the following algorithm by Ramanujan and Chudnovsky...
Please fix this code so it compiles import java.math.BigDecimal; import java.lang.Math; public class Sequence { public static BigDecimal fact( int n ) { BigDecimal result = BigDecimal.ONE; while (n > 0) { result = result.multiply(new BigDecimal(n + "")); n--; } return result; } public static BigDecimal pow( BigDecimal a, int b ) { BigDecimal result = a; if(b == 0) { return BigDecimal.ONE; } while ( b > 1 ) { result = result.multiply(new BigDecimal(a + "")); b--; System.out.print("\n" +...