#On the name of ALLAH and may the blessing and peace of Allah #be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam. #Author : Fouad Teniou #Date : 23/02/10 #version :2.6 """ Pi_approximation uses the subinterval_length function and return its value and yield all the points values while using the subinterval_point function and Pi function compute Pi approximation with 16 decimal places the greater the value of the number the more precise is Pi value """ class Pi_Approximation(object): """ Class that represent Pi approximation """ def __init__(self, number): """ Pi_Approximation constructor takes the number constant """ self.number = number def subinterval_length(self): """ Compute subinterval_length """ sub_length = 2/float(self.number) return sub_length def subinterval_point(self): """ Compute the value of each point """ #attempt to yield all the Xk points values using the subinterval_point try: for item in range(1,self.number + 1): sub_point = -1 + ((item - 1/2.0)* Pi_Approximation.subinterval_length(self)) yield sub_point #Raise TypeError if input is not numerical except TypeError: print "\n