given a positive integer n and a precision factor p it produces an output with a maximum error p from the actual square root of n example given n 5 and p 0 001 can produce output x such that 2 235 x 2 237 actual square root of 5 being 2 236 return square root of n with maximum absolute error epsilon guess n 2 while absguess guess n epsilon guess guess n guess 2 return guess return square root of n with maximum absolute error epsilon
def square_root(n, epsilon=0.001):
    
    guess = n / 2

    while abs(guess * guess - n) > epsilon:
        guess = (guess + (n / guess)) / 2

    return guess