使用二分法(Bisection Method)求平方根。
1 defsqrtBI(x, epsilon):2 assert x>0, 'X must be non-nagtive, not' +str(x)3 assert epsilon > 0, 'epsilon must be postive, not' +str(epsilon)4
5 low =06 high =x7 guess = (low + high)/2.0
8 counter = 1
9 while (abs(guess ** 2 - x) > epsilon) and (counter <= 100):10 if guess ** 2
<<
<