diff --git a/Week02/types_ozgun_kasapoglu.py b/Week02/types_ozgun_kasapoglu.py new file mode 100644 index 00000000..bb8de785 --- /dev/null +++ b/Week02/types_ozgun_kasapoglu.py @@ -0,0 +1,4 @@ +my_int = 230 +my_float = 315.0 +my_bool = True +my_complex = 12j diff --git a/Week03/pyramid_ozgun_kasapoglu.py b/Week03/pyramid_ozgun_kasapoglu.py new file mode 100644 index 00000000..4090bf43 --- /dev/null +++ b/Week03/pyramid_ozgun_kasapoglu.py @@ -0,0 +1,10 @@ +def calculate_pyramid_height(blocks): + height = 0 + blocks_needed = 1 + + while blocks >= blocks_needed: + blocks -= blocks_needed + height += 1 + blocks_needed += 1 + + return height diff --git a/Week03/sequences_ozgun_kasapoglu.py b/Week03/sequences_ozgun_kasapoglu.py new file mode 100644 index 00000000..bf2d99d0 --- /dev/null +++ b/Week03/sequences_ozgun_kasapoglu.py @@ -0,0 +1,19 @@ +def remove_duplicates(my_list): + return list(dict.fromkeys(my_list)) + + +def list_counts(my_list): + counts = {} + for item in my_list: + if item in counts: + counts[item] += 1 + else: + counts[item] = 1 + return counts + + +def reverse_dict(my_dict): + reversed_results = {} + for key, value in my_dict.items(): + reversed_results[value] = key + return reversed_results diff --git a/Week04/decorators_ozgun_kasapoglu.py b/Week04/decorators_ozgun_kasapoglu.py new file mode 100644 index 00000000..a0e3a114 --- /dev/null +++ b/Week04/decorators_ozgun_kasapoglu.py @@ -0,0 +1,32 @@ +import time +import sys +import tracemalloc + +tracemalloc.start() + + +def performance(func): + def wrapper(*args, **kwargs): + performance.counter += 1 + + tracemalloc.reset_peak() + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + performance.total_time += (end_time - start_time) + + _, peak = tracemalloc.get_traced_memory() + obj_size = sys.getsizeof(result) + + performance.total_mem += max(peak, obj_size) + + return result + + return wrapper + + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0.0 diff --git a/Week04/functions_ozgun_kasapoglu.py b/Week04/functions_ozgun_kasapoglu.py new file mode 100644 index 00000000..5d942b29 --- /dev/null +++ b/Week04/functions_ozgun_kasapoglu.py @@ -0,0 +1,32 @@ +custom_power = lambda x=0, /, e=1: float(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: base for the first term + :param y: base for the second term + :param a: exponent for the first term + :param b: exponent for the second term + :param c: divisor for the sum + :return: the result of the equation as float + """ + if type(x) is not int: raise TypeError("x must be int") + if type(y) is not int: raise TypeError("y must be int") + if type(a) is not int: raise TypeError("a must be int") + if type(b) is not int: raise TypeError("b must be int") + if type(c) is not int: raise TypeError("c must be int") + return float((x ** a + y ** b) / c) + +_total = 0 +_counts = {} + + +def fn_w_counter() -> (int, dict[str, int]): + global _total + _total += 1 + caller = __name__ + _counts[caller] = _counts.get(caller, 0) + 1 + + return _total, _counts diff --git a/Week05/awaitme_ozgun_kasapoglu.py b/Week05/awaitme_ozgun_kasapoglu.py new file mode 100644 index 00000000..36cecc24 --- /dev/null +++ b/Week05/awaitme_ozgun_kasapoglu.py @@ -0,0 +1,5 @@ +def awaitme(func): + async def wrapper(*args, **kwargs): + return func(*args, **kwargs) + + return wrapper diff --git a/Week06/timer_ozgun_kasapoglu.py b/Week06/timer_ozgun_kasapoglu.py new file mode 100644 index 00000000..fa2165ce --- /dev/null +++ b/Week06/timer_ozgun_kasapoglu.py @@ -0,0 +1,13 @@ +import time + +class Timer: + def __init__(self): + self.start_time = 0.0 + self.end_time = 0.0 + + def __enter__(self): + self.start_time = time.time() + return self + + def __exit__(self, a, b, c): + self.end_time = time.time()