list = [] for i in range(1,904): temp = '这是第%s页' %i #页码的显示内容 list.append(temp)
# 总共有多少条内容 total = len(list)
# 每页要显示多少条内容 page = 10
用divmod得出总内容条数与每页显示条数的商和余数 max_page,a = divmod(total,page) if a > 0: max_page = max_page + 1 while True: paper = int(input('请输入要查看的页码:')) if paper < 1 or paper > max_page: print('你输入的页码不存在,请输入1~%s页' %max_page) else: start = (paper-1)* page end = paper * page data = list[start:end] for item in data: print(item)