From 5728a98696a6abf89cb97f13e11885e437cab76b Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:28:52 +0300 Subject: [PATCH 1/6] Create types_caner_gundas.py --- Week02/types_caner_gundas.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Week02/types_caner_gundas.py diff --git a/Week02/types_caner_gundas.py b/Week02/types_caner_gundas.py new file mode 100644 index 00000000..e82ae26c --- /dev/null +++ b/Week02/types_caner_gundas.py @@ -0,0 +1,4 @@ +my_int = 21 +my_float = 6.30 +my_bool = True +my_complex = 7 + 1j From 6478103af2ccb8d99ba0d83cc4057011df4a9090 Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:33:04 +0300 Subject: [PATCH 2/6] Create pyramid_caner_gundas.py --- Week03/pyramid_caner_gundas.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Week03/pyramid_caner_gundas.py diff --git a/Week03/pyramid_caner_gundas.py b/Week03/pyramid_caner_gundas.py new file mode 100644 index 00000000..6b7188f7 --- /dev/null +++ b/Week03/pyramid_caner_gundas.py @@ -0,0 +1,8 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + needed_blocks = 1 + while number_of_blocks >= needed_blocks: + number_of_blocks -= needed_blocks + height += 1 + needed_blocks += 1 + return height From f8f8f81962f68d06282f4c318ffbec4de6c939da Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:36:16 +0300 Subject: [PATCH 3/6] Create functions_caner_gundas.py --- Week04/functions_caner_gundas.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Week04/functions_caner_gundas.py diff --git a/Week04/functions_caner_gundas.py b/Week04/functions_caner_gundas.py new file mode 100644 index 00000000..377295a4 --- /dev/null +++ b/Week04/functions_caner_gundas.py @@ -0,0 +1,39 @@ +custom_power = lambda x=0, /, e=1: x**e + + +def custom_equation( + x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1 +) -> float: + """ + This function calculates (x**a + y**b) / c. + + :param x: The first base, positional-only + :type x: int + :param y: The second base, positional-only + :type y: int + :param a: The exponent of x + :type a: int + :param b: The exponent of y + :type b: int + :param c: The divisor, keyword-only + :type c: int + :raises TypeError: If any of the parameters is not an integer + :return: The result of (x**a + y**b) / c + :rtype: float + """ + for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)): + if not isinstance(value, int): + raise TypeError(f"{name} must be an integer") + return (x**a + y**b) / c + + +def fn_w_counter() -> (int, dict[str, int]): + """ + This function counts its calls and returns the total with the callers. + """ + # test_functions expects this module's name, even when called from the test + fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1 + return sum(fn_w_counter.callers.values()), dict(fn_w_counter.callers) + + +fn_w_counter.callers = {} From 15a9e45ab745ae1866eba85fb6b0d9b163195cf4 Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:41:03 +0300 Subject: [PATCH 4/6] Create decorators_caner_gundas.py --- Week04/decorators_caner_gundas.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Week04/decorators_caner_gundas.py diff --git a/Week04/decorators_caner_gundas.py b/Week04/decorators_caner_gundas.py new file mode 100644 index 00000000..a45590d4 --- /dev/null +++ b/Week04/decorators_caner_gundas.py @@ -0,0 +1,31 @@ +import functools +import time +import tracemalloc + + +def performance(fn): + """ + This decorator measures the time and memory of the calls of a function. + The statistics of all decorated functions are saved in its attributes. + """ + + @functools.wraps(fn) + def wrapper(*args, **kwargs): + # shortcut: a decorated function calling another one under-reports + # memory because tracemalloc is global, keep calls flat to stay exact + tracemalloc.start() + start = time.perf_counter() + try: + return fn(*args, **kwargs) + finally: + performance.total_time += time.perf_counter() - start + performance.total_mem += tracemalloc.get_traced_memory()[1] + performance.counter += 1 + tracemalloc.stop() + + return wrapper + + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 From 07b3e7ea2e8ad23bba1379c82e875515ef4f0264 Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:43:39 +0300 Subject: [PATCH 5/6] Create emails_caner_gundas.py --- Week05/emails_caner_gundas.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Week05/emails_caner_gundas.py diff --git a/Week05/emails_caner_gundas.py b/Week05/emails_caner_gundas.py new file mode 100644 index 00000000..9b14347e --- /dev/null +++ b/Week05/emails_caner_gundas.py @@ -0,0 +1,35 @@ +import re + + +class Emails(list): + """ + This class keeps a list of unique and valid email addresses. + """ + + def __init__(self, emails: list) -> None: + super().__init__(self.validate(emails)) + + @property + def data(self) -> "Emails": + """ + This property returns the email addresses. + """ + return self + + @staticmethod + def validate(emails: list) -> list: + """ + This method checks the email addresses and removes the duplicates. + """ + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not re.fullmatch(r"[\w.+-]+@[\w-]+(\.[\w-]+)+", email): + raise ValueError(f"{email!r} is not a valid email address") + return list(dict.fromkeys(emails)) + + def __repr__(self) -> str: + return f"Emails({list(self)!r})" + + def __str__(self) -> str: + return ", ".join(self) From 5b77d6bc57843ba074bfc022650289ed8f317645 Mon Sep 17 00:00:00 2001 From: canergundas <230316044@ogr.cbu.edu.tr> Date: Wed, 18 Nov 2026 20:44:59 +0300 Subject: [PATCH 6/6] Create sequences_caner_gundas.py --- Week03/sequences_caner_gundas.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week03/sequences_caner_gundas.py diff --git a/Week03/sequences_caner_gundas.py b/Week03/sequences_caner_gundas.py new file mode 100644 index 00000000..ae31fb73 --- /dev/null +++ b/Week03/sequences_caner_gundas.py @@ -0,0 +1,26 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {value: key for key, value in d.items()}