二分法猜数字

寻找一个要求中的数字

x=int(input('enter an integer between 0-100:'))
low=0
high=101
mid=int((low+high)/2)
guess=mid
while x!=guess:
    if mid>x:
        high=mid
        mid=int((low+high)/2)
        guess=mid
    else:
        low=mid
        mid=int((low + high) / 2)
        guess=mid
print('the number you input is '+str(guess))

在这里插入图片描述

你可能感兴趣的:(二分法猜数字)