def sqrt(x, tolerance=0.0000001):
    """
    Find a value r with r*r within tolerance of x.
    """
    l = 0.0
    r = float(x)
    while r-l > tolerance:
        m = l + 0.5*(r-l)
        s = m*m
        if s < x:
            l = m
        else:
            r = m
    return l