二分法查找*似*方根
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 )
负重前行
posted on 2020-07-08 16:33 菲菲菲非常可爱的小白兔 阅读(102) 评论(0) 编辑 收藏 举报