求解,用二分法求根
import math
x = input(‘please input a number’)
x = float(x)
a = math.sqrt(x)
b = math.ceil(a)
d=float(b)
low=0
high=float(d)
c = (high+low)/2
x=0
while x<=20:
if a>c:
high=d,low=c
c=(high+low)/2
x=x+1
if x==20:
print(low,high)
elif a==c:
print(c)
else:
high=c
c = (high + low) / 2
x=x+1
if x==20:
print(low,high)
为什么迭代错误