1.

Create a function that computes the approximation of pi, based on the number of iterations specified, pi can be computed by 4*(l-l/3+l/5-l/7+l/9-…).

Answer»

def piApprox(num):

i = 1

pi = 0

while i<=num:

#set ‘while’ termination condition

pi +=((4/float(2*i-l)n-l)**(i+l))

#compute the ith term of the series

i+=l # update i

return pi



Discussion

No Comment Found