I wrote a program to solve square root with the newton`s algorithm (square root of x, take a guess, keep doing g + x/g until it`s good enough. It is like this:
x = input("i want the sqrrt of:")
def average (a, b):
av = (a+b)/2.0
return av
def improve (g, x):
i = average (g, x/g)
return i
def ge (g, x):
d = abs((g*g)-x)
return (d == 0)
def sqrroot (g, x):
while (not ge (g, x)):
improve (g, x)
return g
def sqrt (x):
a = sqrroot (1, x)
return a
print sqrt (x)
When I try to run it on terminal it does nothing ! it takes the first input and i need to open another terminal because it came useless, cant do nothing and it doesnt give me response.
this program is working right if i do it direct on a python terminal, but i wanted to save it and run later
Bookmarks