From 70a23960e56bbd5490078287bf3698db41120a6c Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 28 Oct 2026 21:11:34 +0300 Subject: [PATCH 1/8] hw 4 functions --- Week04/functions_hilmican_karadag.py | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Week04/functions_hilmican_karadag.py diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py new file mode 100644 index 00000000..2e2ae8f0 --- /dev/null +++ b/Week04/functions_hilmican_karadag.py @@ -0,0 +1,63 @@ +import inspect + +# x is positional-only (default 0), e is positional-or-keyword (default 1) +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: + """ + Calculate (x**a + y**b) / c. + + :param x: Positional-only base of the first term. + :type x: int + :param y: Positional-only base of the second term. + :type y: int + :param a: Exponent applied to x. + :type a: int + :param b: Exponent applied to y. + :type b: int + :param c: Keyword-only divisor. + :type c: int + :return: The value of (x**a + y**b) / c. + :rtype: float + """ + return (x**a + y**b) / c + + +_total_calls: int = 0 +_calls_by_caller: dict[str, int] = {} + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + """ + Count how many times this function has been called, and by whom. + + :return: A tuple of the total number of calls and a dictionary mapping + each caller's ``__name__`` to the number of calls it made. + :rtype: tuple[int, dict[str, int]] + """ + global _total_calls + caller = inspect.currentframe().f_back.f_globals["__name__"] + _total_calls += 1 + _calls_by_caller[caller] = _calls_by_caller.get(caller, 0) + 1 + return _total_calls, dict(_calls_by_caller) + + +if __name__ == "__main__": + assert custom_power(2) == 2 + assert custom_power(2, 3) == 8 + assert custom_power(2, e=2) == 4 + + assert custom_equation(2, 3) == 5.0 + assert custom_equation(2, 3, 2) == 7.0 + assert custom_equation(2, 3, 2, 3) == 31.0 + assert custom_equation(3, 5, a=2, b=3, c=4) == 33.5 + assert custom_equation(3, 5, 2, b=3, c=4) == 33.5 + assert custom_equation(3, 5, 2, 3, c=4) == 33.5 + + for i in range(10): + fn_w_counter() + assert fn_w_counter() == (11, {"__main__": 11}) + print("All examples pass.") \ No newline at end of file From 06755b1725fbd1f497625de6f6234a127a3d8b1b Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:15:24 +0300 Subject: [PATCH 2/8] Update functions_hilmican_karadag.py --- Week04/functions_hilmican_karadag.py | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py index 2e2ae8f0..8587f53b 100644 --- a/Week04/functions_hilmican_karadag.py +++ b/Week04/functions_hilmican_karadag.py @@ -1,15 +1,15 @@ import inspect - + # x is positional-only (default 0), e is positional-or-keyword (default 1) 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: """ Calculate (x**a + y**b) / c. - + :param x: Positional-only base of the first term. :type x: int :param y: Positional-only base of the second term. @@ -24,16 +24,16 @@ def custom_equation( :rtype: float """ return (x**a + y**b) / c - - + + _total_calls: int = 0 _calls_by_caller: dict[str, int] = {} - - -def fn_w_counter() -> tuple[int, dict[str, int]]: + + +def fn_w_counter() -> (int, dict[str, int]): """ Count how many times this function has been called, and by whom. - + :return: A tuple of the total number of calls and a dictionary mapping each caller's ``__name__`` to the number of calls it made. :rtype: tuple[int, dict[str, int]] @@ -43,21 +43,21 @@ def fn_w_counter() -> tuple[int, dict[str, int]]: _total_calls += 1 _calls_by_caller[caller] = _calls_by_caller.get(caller, 0) + 1 return _total_calls, dict(_calls_by_caller) - - + + if __name__ == "__main__": assert custom_power(2) == 2 assert custom_power(2, 3) == 8 assert custom_power(2, e=2) == 4 - + assert custom_equation(2, 3) == 5.0 assert custom_equation(2, 3, 2) == 7.0 assert custom_equation(2, 3, 2, 3) == 31.0 assert custom_equation(3, 5, a=2, b=3, c=4) == 33.5 assert custom_equation(3, 5, 2, b=3, c=4) == 33.5 assert custom_equation(3, 5, 2, 3, c=4) == 33.5 - + for i in range(10): fn_w_counter() assert fn_w_counter() == (11, {"__main__": 11}) - print("All examples pass.") \ No newline at end of file + print("All examples pass.") From 7734bb1a9e7e920c26ab4ddbadc6c69342ec7d70 Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:15:54 +0300 Subject: [PATCH 3/8] Update functions_hilmican_karadag.py From a5bd17c3e714283b91d414690ef539d6c925dc61 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 28 Oct 2026 21:17:17 +0300 Subject: [PATCH 4/8] Delete functions_hilmican_karadag.py --- Week04/functions_hilmican_karadag.py | 63 ---------------------------- 1 file changed, 63 deletions(-) delete mode 100644 Week04/functions_hilmican_karadag.py diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py deleted file mode 100644 index 2e2ae8f0..00000000 --- a/Week04/functions_hilmican_karadag.py +++ /dev/null @@ -1,63 +0,0 @@ -import inspect - -# x is positional-only (default 0), e is positional-or-keyword (default 1) -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: - """ - Calculate (x**a + y**b) / c. - - :param x: Positional-only base of the first term. - :type x: int - :param y: Positional-only base of the second term. - :type y: int - :param a: Exponent applied to x. - :type a: int - :param b: Exponent applied to y. - :type b: int - :param c: Keyword-only divisor. - :type c: int - :return: The value of (x**a + y**b) / c. - :rtype: float - """ - return (x**a + y**b) / c - - -_total_calls: int = 0 -_calls_by_caller: dict[str, int] = {} - - -def fn_w_counter() -> tuple[int, dict[str, int]]: - """ - Count how many times this function has been called, and by whom. - - :return: A tuple of the total number of calls and a dictionary mapping - each caller's ``__name__`` to the number of calls it made. - :rtype: tuple[int, dict[str, int]] - """ - global _total_calls - caller = inspect.currentframe().f_back.f_globals["__name__"] - _total_calls += 1 - _calls_by_caller[caller] = _calls_by_caller.get(caller, 0) + 1 - return _total_calls, dict(_calls_by_caller) - - -if __name__ == "__main__": - assert custom_power(2) == 2 - assert custom_power(2, 3) == 8 - assert custom_power(2, e=2) == 4 - - assert custom_equation(2, 3) == 5.0 - assert custom_equation(2, 3, 2) == 7.0 - assert custom_equation(2, 3, 2, 3) == 31.0 - assert custom_equation(3, 5, a=2, b=3, c=4) == 33.5 - assert custom_equation(3, 5, 2, b=3, c=4) == 33.5 - assert custom_equation(3, 5, 2, 3, c=4) == 33.5 - - for i in range(10): - fn_w_counter() - assert fn_w_counter() == (11, {"__main__": 11}) - print("All examples pass.") \ No newline at end of file From c063f12741c512816383a7465548cd882c78fff7 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 28 Oct 2026 21:18:57 +0300 Subject: [PATCH 5/8] Update functions_hilmican_karadag.py --- Week04/functions_hilmican_karadag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py index 8587f53b..1d0086b3 100644 --- a/Week04/functions_hilmican_karadag.py +++ b/Week04/functions_hilmican_karadag.py @@ -60,4 +60,4 @@ def fn_w_counter() -> (int, dict[str, int]): for i in range(10): fn_w_counter() assert fn_w_counter() == (11, {"__main__": 11}) - print("All examples pass.") + print("All examples pass.") \ No newline at end of file From 0d89bbad2091f3ae77e0e943488fca0657ddac38 Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:29:19 +0300 Subject: [PATCH 6/8] Update functions_hilmican_karadag.py --- Week04/functions_hilmican_karadag.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py index 1d0086b3..db94226a 100644 --- a/Week04/functions_hilmican_karadag.py +++ b/Week04/functions_hilmican_karadag.py @@ -60,4 +60,3 @@ def fn_w_counter() -> (int, dict[str, int]): for i in range(10): fn_w_counter() assert fn_w_counter() == (11, {"__main__": 11}) - print("All examples pass.") \ No newline at end of file From d3f58bb82dd42d131acdedcd64960b7f195e9b5f Mon Sep 17 00:00:00 2001 From: hilmican karadag <121621092+hilmicankaradag@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:37:34 +0300 Subject: [PATCH 7/8] Update functions_hilmican_karadag.py --- Week04/functions_hilmican_karadag.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Week04/functions_hilmican_karadag.py b/Week04/functions_hilmican_karadag.py index db94226a..aab402a0 100644 --- a/Week04/functions_hilmican_karadag.py +++ b/Week04/functions_hilmican_karadag.py @@ -1,5 +1,3 @@ -import inspect - # x is positional-only (default 0), e is positional-or-keyword (default 1) custom_power = lambda x=0, /, e=1: x**e @@ -39,9 +37,8 @@ def fn_w_counter() -> (int, dict[str, int]): :rtype: tuple[int, dict[str, int]] """ global _total_calls - caller = inspect.currentframe().f_back.f_globals["__name__"] _total_calls += 1 - _calls_by_caller[caller] = _calls_by_caller.get(caller, 0) + 1 + _calls_by_caller[__name__] = _calls_by_caller.get(__name__, 0) + 1 return _total_calls, dict(_calls_by_caller) @@ -60,3 +57,4 @@ def fn_w_counter() -> (int, dict[str, int]): for i in range(10): fn_w_counter() assert fn_w_counter() == (11, {"__main__": 11}) + print("All examples pass.") From 0b765bdc110ef7d5727d7a046a3e092782457333 Mon Sep 17 00:00:00 2001 From: hilmican karadag Date: Wed, 28 Oct 2026 21:39:11 +0300 Subject: [PATCH 8/8] Create emails_hilmican_karadag.py --- Week05/emails_hilmican_karadag.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week05/emails_hilmican_karadag.py diff --git a/Week05/emails_hilmican_karadag.py b/Week05/emails_hilmican_karadag.py new file mode 100644 index 00000000..9aa2ddf2 --- /dev/null +++ b/Week05/emails_hilmican_karadag.py @@ -0,0 +1,30 @@ +import re + + +class Emails(list): + + EMAIL_PATTERN = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+") + + def __init__(self, emails): + super().__init__() + self.validate(emails) + for email in emails: + if email not in self: # tekrar edenleri ekleme + self.append(email) + + @property + def data(self): + return list(self) + + def validate(self, emails): + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not self.EMAIL_PATTERN.fullmatch(email): + raise ValueError(f"{email!r} is not a valid email address") + + def __repr__(self): + return f"Emails({list.__repr__(self)})" + + def __str__(self): + return ", ".join(self) \ No newline at end of file