From 065447534c9b64df66737adf0e4c017183f76ec7 Mon Sep 17 00:00:00 2001 From: leart-ramushi Date: Wed, 11 Mar 2026 14:58:57 +0100 Subject: [PATCH 1/2] Abgabe Aufgabe 3 --- src/codewars/pagination_helper.py | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/codewars/pagination_helper.py diff --git a/src/codewars/pagination_helper.py b/src/codewars/pagination_helper.py new file mode 100644 index 0000000..a30f50c --- /dev/null +++ b/src/codewars/pagination_helper.py @@ -0,0 +1,43 @@ +# Abgabe - PaginationHelper Aufgabe von Codewars +# Link dazu: https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1 +# Leart Ramushi + +# TODO: complete this class +import math + + +class PaginationHelper: + + # The constructor takes in an array of items and an integer indicating + # how many items fit within a single page + def __init__(self, collection, items_per_page): + self.collection = collection + self.items_per_page = items_per_page + + # returns the number of items within the entire collection + def item_count(self): + return len(self.collection) + + # returns the number of pages + def page_count(self): + return math.ceil(len(self.collection) / self.items_per_page) + + # returns the number of items on the given page. page_index is zero based + # this method should return -1 for page_index values that are out of range + def page_item_count(self, page_index): + if page_index < 0 or page_index >= self.page_count(): + return -1 + if page_index == self.page_count() - 1: + rest = len(self.collection) % self.items_per_page + if rest == 0: + return self.items_per_page + else: + return rest + return 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): + if item_index < 0 or item_index >= len(self.collection): + return -1 + return item_index // self.items_per_page -- 2.30.2 From 65a4c799166f35cbd26d92ae4f9bcd5cfe36e004 Mon Sep 17 00:00:00 2001 From: leart-ramushi Date: Wed, 11 Mar 2026 15:02:02 +0100 Subject: [PATCH 2/2] Link Korrektur im Kommentar --- src/codewars/pagination_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codewars/pagination_helper.py b/src/codewars/pagination_helper.py index a30f50c..68f524b 100644 --- a/src/codewars/pagination_helper.py +++ b/src/codewars/pagination_helper.py @@ -1,5 +1,5 @@ # Abgabe - PaginationHelper Aufgabe von Codewars -# Link dazu: https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1 +# Link dazu: https://www.codewars.com/kata/515bb423de843ea99400000a # Leart Ramushi # TODO: complete this class -- 2.30.2