From 00a42ea0fd8ede1c9fd572551e7f165ac7d1bff6 Mon Sep 17 00:00:00 2001 From: zimmersandro Date: Mon, 9 Mar 2026 21:19:09 +0100 Subject: [PATCH] fix: fixed function page_item_count. from calculating: constant * muliplicator * 2. to: constant * multiplicator + constant. first calculation returned wrong amount of items to return --- src/codewars/kata_pagination_helper.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/codewars/kata_pagination_helper.py b/src/codewars/kata_pagination_helper.py index 3be65a3..454c50f 100644 --- a/src/codewars/kata_pagination_helper.py +++ b/src/codewars/kata_pagination_helper.py @@ -30,18 +30,20 @@ class PaginationHelper: return len( self.collection[ - self.items_per_page * page_index : self.items_per_page * page_index * 2 + self.items_per_page * page_index : self.items_per_page * page_index + + self.items_per_page ] ) # determines what page an item at the given index is on. Zero based indexes. # this method should return -1 for item_index values that are out of range def page_index(self, item_index): - pass + try: + self.collection[item_index] + if item_index < 0: + raise IndexError + except IndexError: + return -1 -collection = ["a", "b", "c", "d", "e", "f"] -helper = PaginationHelper(collection, 4) - -print(helper.page_count()) -print(helper.page_item_count(1)) + return item_index // self.items_per_page