diff --git a/Week02/types_yigithan_erken.py b/Week02/types_yigithan_erken.py new file mode 100644 index 000000000..f64e80967 --- /dev/null +++ b/Week02/types_yigithan_erken.py @@ -0,0 +1,4 @@ +my_int = 1903 +my_float = 19.03 +my_bool = True +my_complex = 190 + 3j \ No newline at end of file diff --git a/Week03/pyramid_yigithan_erken.py b/Week03/pyramid_yigithan_erken.py new file mode 100644 index 000000000..dae611cdb --- /dev/null +++ b/Week03/pyramid_yigithan_erken.py @@ -0,0 +1,8 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + used = 1 + while number_of_blocks >= used: + number_of_blocks -= used + height += 1 + used += 1 + return height diff --git a/Week03/sequences_yigithan_erken.py b/Week03/sequences_yigithan_erken.py new file mode 100644 index 000000000..6b9827b5a --- /dev/null +++ b/Week03/sequences_yigithan_erken.py @@ -0,0 +1,17 @@ +def remove_duplicates(seq: list) -> list: + return list(set(seq)) + +def list_counts(seq: list) -> dict: + counts = {} + for item in seq: + if item in counts: + counts[item] += 1 + else: + counts[item] = 1 + return counts + +def reverse_dict(d: dict) -> dict: + reversed_dict = {} + for key, value in d.items(): + reversed_dict[value] = key + return reversed_dict \ No newline at end of file diff --git a/Week04/decorators_yigithan_erken.py b/Week04/decorators_yigithan_erken.py new file mode 100644 index 000000000..67ba79793 --- /dev/null +++ b/Week04/decorators_yigithan_erken.py @@ -0,0 +1,31 @@ +import time +import tracemalloc + +def performance(func): + + def wrapper(*args, **kwargs): + + tracemalloc.start() + start = time.perf_counter() + start_mem = tracemalloc.get_traced_memory()[0] + tracemalloc.reset_peak() + + try: + result = func(*args, **kwargs) + + finally: + end = time.perf_counter() + current, peak = tracemalloc.get_traced_memory() + + performance.counter += 1 + performance.total_time += end - start + performance.total_mem += peak - start_mem + + tracemalloc.stop() + + return result + return wrapper + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 \ No newline at end of file diff --git a/Week04/functions_yigithan_erken.py b/Week04/functions_yigithan_erken.py new file mode 100644 index 000000000..33df1315b --- /dev/null +++ b/Week04/functions_yigithan_erken.py @@ -0,0 +1,33 @@ +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: + """ + Calculates a custom equation. + + :param x: Positional-only integer, defaults to 0. + :param y: Positional-only integer, defaults to 0. + :param a: Positional-or-keyword integer, defaults to 1. + :param b: Positional-or-keyword integer, defaults to 1. + :param c: Keyword-only integer, defaults to 1. + :return: The result of (x**a + y**b) / c as float. + """ + if not all(isinstance(val, int) for val in (x, y, a, b, c)): + raise TypeError("Arguments must be integers.") + + return float((x**a + y**b) / c) + +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter, "total_calls"): + fn_w_counter.total_calls = 0 + fn_w_counter.caller_counts = {} + + caller_name = __name__ + + fn_w_counter.total_calls += 1 + + if caller_name in fn_w_counter.caller_counts: + fn_w_counter.caller_counts[caller_name] += 1 + else: + fn_w_counter.caller_counts[caller_name] = 1 + + return (fn_w_counter.total_calls, fn_w_counter.caller_counts) \ No newline at end of file diff --git a/Week05/emails_yigithan_erken.py b/Week05/emails_yigithan_erken.py new file mode 100644 index 000000000..e67f2d739 --- /dev/null +++ b/Week05/emails_yigithan_erken.py @@ -0,0 +1,27 @@ +class Emails(list): + def __init__(self, initial_emails=None): + super().__init__() + self.data = self + if initial_emails is not None: + self.validate(initial_emails) + + def validate(self, emails_to_check): + for item in emails_to_check: + if not isinstance(item, str): + raise ValueError("List can only contain strings") + + if "@" not in item: + raise ValueError("Invalid email format") + + domain_part = item.split("@")[1] + if "." not in domain_part: + raise ValueError("Invalid email format") + + if item not in self: + self.append(item) + + def __repr__(self): + return f"Emails({super().__repr__()})" + + def __str__(self): + return super().__str__() \ No newline at end of file