@ajeet sahu - what you do not seem to understand is that the script you have shown IS performing the correct iterations, The problem is with the convergence test. But more importantly, you will need to decide what it means to YOU for the convergence test to terminate. Until YOU state a clear definition of what it means for you to get the convergence you want, then code cannot be written without a clear definition.
I''ve plotted below what the successive approximations do, by looking at a specific digit here:
I've plotted that second digit here. As you can see, it seems to be around iteration 625 or so that 4 becomes stable, but it was osillating between 3 and 4 from roughly iteration 120. So the very firsst time a 4 appears after 3.1, is roughly iteration 120.
Now, look at the next digit. When does it stabilize?
Here we see that a 1 in that place begins to appear around iteration 1700, but that third digit is now oscilating between 1 and 2 for a long time. It is close to iteration 2500 before we get a stable digit 1 at that point. The problem is, if we look at pi itself, 3.142 is actually CLOSER to the true value of pi than is 3.141. So can we say that 3.141 has converged? This is the problem with your tolerance test. Your convergence test is looking to see if the absolute error in the approximation to pi is within a specific tolerance, and stopping as soon as that happens.
I could also plot the next digit, as found by that approximation. etc. But you need to decide what convergence means to you. And probably, you need to decide what it means to your teacher, because that is who will be grading your solution.
So next, consider the absolute error, thus your approximation minus pi. When does that error, which is oscillating in sign at EVERY iteration, become ssufficiently small in absolute value at some point?
As you can see from this last figure, I had to use a log scale on the y axis, because the numbers become small. But if you are looking only at the difference from ground truth, at what point would you determine the series has finally converged?
We cannot give you a convergence test until you know yourself, and you explain in clear words, what it means for that approximation to have converged. Typically, is is simply absolute convergence that is used, so one might use the absolute difference between truth and the approximation, and when that difference is first less than some tolerance value. But that does NOT gaurantee that a specific digit is correct. As you see from the plots I have shown, any given digit will oscillate for quite a while before it settles into a fixed value.
So your problem is within your own mind, and only there. Until you explain what it means for convergence, and until you explain what you think your teacher means for that to happen, nobody can help you.