大家好,我刚开始使用 python 编程。我写了这个通用代码,它会一直二等分,直到找到正确的数字。但它不起作用。代码一直在块内徘徊“如果猜测
num=raw_input("choose a number between 0-100 ")
l=0 #lower limit
u=100 #upper limit
guess=(l+u)/2
print num
print "is it =",guess
while guess!=num:
if guess==num:
break
if guess<num:
l=guess
guess=(l+u)/2
print "guessed low,new guess = ",guess
elif guess>num:
u=guess
guess=(u+l)/2
print "guessed high,new guess = ",guess