def sqrt(x): guess = 1.0 while abs(guess * guess - x) > 0.001: guess = (guess + x / guess) / 2 return guess