[ create a new paste ] login | about

Link: http://codepad.org/dDMvsIM7    [ raw code | output | fork ]

Python, pasted on Sep 26:
1
2
3
4
5
6
7
8
def square_root(a,n):
        x0=1
	arr=[]
	for i in range(n):
		arr.append(x0)
		x0=0.5*(x0+a/x0)
        return arr
print square_root(2,10)


Output:
1
[1, 1.5, 1.4166666666666665, 1.4142156862745097, 1.4142135623746899, 1.4142135623730949, 1.4142135623730949, 1.4142135623730949, 1.4142135623730949, 1.4142135623730949]


Create a new paste based on this one


Comments: