二分法查找*似*方根

x = 25

epsilon = 0.01

numguess = 0

low = 0.0

high = max(1.0,x)

ans = (high + low )/2

while abs(ans**2 -x ) >=epsilon:

  numguess +=1

  if ans**2 < x:

    low = ans

  else:

    high = ans

  ans = (high + low )/2.0

print(ans, 'is close to square root of ', x )

负重前行
原文地址:https://www.cnblogs.com/astride/p/13267729.html