a= float(input ("请输入您要开平方的数:\n")) if a > 0: if a>1: low = 0 high = a guess = (low + high) / 2 while abs(guess **2 - a)> 1e-5: if guess ** 2>a: high= guess else : low = guess guess = (low + high) / 2 print(guess) else: low = a high = 1 guess = (low + high)/2 while abs(guess ** 2 -a)> 1e-5: if guess**2 > a: high=guess else: low= guess guess = (low + high)/2 print (guess) else : print("请输入恰当的值")
pyhon3 二分法求算术平方根
最新推荐文章于 2023-06-29 20:38:00 发布