From 5427e117bd46b72da97d7bc3fe413fb86d9d0c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sefa=20Sa=C4=9F=C4=B1rl=C4=B1?= Date: Sat, 7 Nov 2026 00:50:35 +0300 Subject: [PATCH] =?UTF-8?q?Week03:=20pyramid=20ve=20sequences=20=C3=B6devl?= =?UTF-8?q?eri=20eklendi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week03/pyramid_sefa_sagirli.py | 10 ++++++++++ Week03/sequences_sefa_sagirli.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Week03/pyramid_sefa_sagirli.py create mode 100644 Week03/sequences_sefa_sagirli.py diff --git a/Week03/pyramid_sefa_sagirli.py b/Week03/pyramid_sefa_sagirli.py new file mode 100644 index 00000000..6807d1f3 --- /dev/null +++ b/Week03/pyramid_sefa_sagirli.py @@ -0,0 +1,10 @@ +def calculate_pyramid_height(number_of_blocks): + """Return the height of the pyramid that can be built with the given blocks. + + Each level i needs i blocks (1 on top, 2 below it, and so on). + """ + height = 0 + while number_of_blocks >= height + 1: + height += 1 + number_of_blocks -= height + return height diff --git a/Week03/sequences_sefa_sagirli.py b/Week03/sequences_sefa_sagirli.py new file mode 100644 index 00000000..11610b4c --- /dev/null +++ b/Week03/sequences_sefa_sagirli.py @@ -0,0 +1,20 @@ +def remove_duplicates(seq: list) -> list: + """Return a new list without duplicates, keeping the original order.""" + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """Return a dictionary with the number of occurrences of each item.""" + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """Return a dictionary with keys and values swapped.""" + return {value: key for key, value in d.items()}