Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write easy and clean code for me. I just start to study Python and I have

ID: 3722502 • Letter: P

Question

Please write easy and clean code for me. I just start to study Python and I have no idea what to write.

Exercise 7.3. The mathematician Srinivasa Ramanujanfound an infinite series that can be used to generate a numerical approximation of 1 / : 1-2y2 0, (4k)(11034 26390k) T 9801(k)-396 k-0 Write a function called estimat e-pi that uses this formula to compute and return an estimate of T. It should use a while loop to compute terms of the summation until the last term is smaller than 1e- 15 (which is Python notation for 10-15). You can check the result by comparing it to math.pi Solution: http://thinkpython2. com/ code/pi. py

Explanation / Answer

**************Below given Code can be used on Python version 2.7 or 3.5************************

# used to calculate factorial, and find exact value of PI
import math

def estimate_pi():
   currentValue = 0 # Value of each element in summation

   totalSum = 0 # summation value
   k = 0

   while True:
       fatorial4K = math.factorial(4*k)    # factorial of 4*k
       factorialK = math.factorial(k)       # factorial of k
       numerator = (fatorial4K * (1103 + 22390*k)) # finds the numerator of element in summation
       denominator = (factorialK**4) * (396**(4*k)) # finds the denominator of element in summation
       currentValue = numerator/denominator # value of element in summation
      
       totalSum = totalSum + currentValue
       k = k+1

       if currentValue < 1e-15: # check if value is less the 1e-15
           break # get out of loop

   # value of 1/pi
   * math.sqrt(2) * totalSum)/ 9801

   # Calculated Value of PI
   myPiValue = 1/oneByPi
   print("My PI Value: ",myPiValue)

   # exact value of PI
   print("Exact PI value : ",math.pi)

   # returns Our calculated value of PI
   return myPiValue


# calling our function written above
estimate_pi()

****************************************

Output of Code:

My PI Value: 3.1415926647087704
Exact PI value : 3.141592653589793