diff --git a/Week02/types_cagatay_karadag.py b/Week02/types_cagatay_karadag.py new file mode 100644 index 00000000..7d71324b --- /dev/null +++ b/Week02/types_cagatay_karadag.py @@ -0,0 +1,4 @@ +my_int = 10 +my_float = 16.18 +my_bool = True +my_complex = 3 + 2j diff --git a/Week03/pyramid_cagatay_karadag.py b/Week03/pyramid_cagatay_karadag.py new file mode 100644 index 00000000..6b7188f7 --- /dev/null +++ b/Week03/pyramid_cagatay_karadag.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 diff --git a/Week04/decorators_cagatay_karadag.py b/Week04/decorators_cagatay_karadag.py new file mode 100644 index 00000000..45e52880 --- /dev/null +++ b/Week04/decorators_cagatay_karadag.py @@ -0,0 +1,23 @@ +import time +import tracemalloc + + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + start = time.perf_counter() + try: + return func(*args, **kwargs) + finally: + elapsed = time.perf_counter() - start + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + performance.counter += 1 + performance.total_time += elapsed + performance.total_mem += peak + return wrapper + + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 diff --git a/Week04/functions_cagatay_karadag.py b/Week04/functions_cagatay_karadag.py new file mode 100644 index 00000000..1fec7d38 --- /dev/null +++ b/Week04/functions_cagatay_karadag.py @@ -0,0 +1,27 @@ +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 (x**a + y**b) / c. + + :param x: First base, positional-only + :param y: Second base, positional-only + :param a: Exponent of x + :param b: Exponent of y + :param c: Divisor, keyword-only + :return: Result of (x**a + y**b) / c + """ + return (x ** a + y ** b) / c + + +_total_calls = 0 +_callers = {} + + +def fn_w_counter() -> (int, dict[str, int]): + global _total_calls + caller = __name__ + _total_calls += 1 + _callers[caller] = _callers.get(caller, 0) + 1 + return _total_calls, _callers diff --git a/Week05/emails_cagatay_karadag.py b/Week05/emails_cagatay_karadag.py new file mode 100644 index 00000000..bd0ab86f --- /dev/null +++ b/Week05/emails_cagatay_karadag.py @@ -0,0 +1,30 @@ +class Emails(list): + + def __init__(self, data): + self.data = self.validate(data) + super().__init__(self.data) + + + def validate(self,data): + temiz=[] + for i in data: + + if not isinstance(i,str): + raise ValueError + elif i.count("@") != 1 : + raise ValueError + elif "." not in i.split("@")[1] : + raise ValueError + else: + if i not in temiz: + temiz.append(i) + + + return temiz + + + def __str__(self): + return f"Emails: {', '.join(self.data)}" + + def __repr__(self): + return f"Emails({self.data})"