第14291题 程序题
补全Python二分查找程序,实现图书馆书号排名查询

学校图书馆为方便查找管理书籍,给定有序书号列表 [8,9,10,12,13,14,16,17,25,27],输入书号后查询该书号的排名(排名从1开始计数)。

示例:输入 12,输出:要查找的书号12排第4

请补全以下Python程序:

lst = [8,9,10,12,13,14,16,17,25,27]
hm = int(input('请输入书本号码'))
①
i,j = 0, n-1
b = -1
while ② :
    m = (i + j) // 2
    if ③ :
        b = m
        break
    elif hm > lst[m]:
        ④
    else:
        j = m - 1
if b == -1:
    print('要查找的书号['+str(hm)+']不在列表lst中。')
else:
    print('要查找的书号['+str(hm)+']排第'+ ⑤ )
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
编辑模式
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析