Please find time to answer this question.
When I print the following code, my while loop does not show any output.
import math
epsilon=.000000001
def mysqrt(a):
while True:
x=a/2
y=(x+a/x)/2
if abs(y-x)<epsilon:
return (y)
def test_square_root():
a=1.0
print ('a'," " , "mysqrt(a)", " ", "math.sqrt(a)", " ", "diff")
while a<10.0:
print (a," " , mysqrt(a), math.sqrt(a),abs(mysqrt(a)-math.sqrt(a)))
a+=1
test_square_root()
For the time being, I am not concthe erned about formatting of the table. I just need the following output. I am using the square root formula y=(x+a/x)/2
a mysqrt(a) math.sqrt(a) diff
1.0 1.0 1.0 0.0
2.0 1.41421356237 1.41421356237 2.22044604925e-16
3.0 1.73205080757 1.73205080757 0.0
4.0 2.0 2.0 0.0
5.0 2.2360679775 2.2360679775 0.0
6.0 2.44948974278 2.44948974278 0.0
7.0 2.64575131106 2.64575131106 0.0
8.0 2.82842712475 2.82842712475 4.4408920985e-16
9.0 3.0 3.0 0.0
I have modified your code slightly and the code is working for me