diff --git "a/Week01/info_ibrahim_\303\266zel.py" "b/Week01/info_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..f45a339c --- /dev/null +++ "b/Week01/info_ibrahim_\303\266zel.py" @@ -0,0 +1,2 @@ +student_id = "220316056" +full_name = "İbrahim Özel" diff --git "a/Week02/types_ibrahim_\303\266zel.py" "b/Week02/types_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..2c22742f --- /dev/null +++ "b/Week02/types_ibrahim_\303\266zel.py" @@ -0,0 +1,4 @@ +my_int = 32 +my_float = 3.32 +my_bool = True +my_complex = 3 + 2j diff --git "a/Week03/pyramid_ibrahim_\303\266zel.py" "b/Week03/pyramid_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..55fc064c --- /dev/null +++ "b/Week03/pyramid_ibrahim_\303\266zel.py" @@ -0,0 +1,9 @@ +def calculate_pyramid_height(number_of_blocks): + height = 0 + blocks = 0 + + while blocks + height + 1 <= number_of_blocks: + height += 1 + blocks += height + + return height diff --git "a/Week03/sequences_ibrahim_\303\266zel.py" "b/Week03/sequences_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..ef181f2c --- /dev/null +++ "b/Week03/sequences_ibrahim_\303\266zel.py" @@ -0,0 +1,20 @@ +def remove_duplicates(seq: list) -> list: + + result = [] + for item in seq: + if item not in result: + result.append(item) + return result + + +def list_counts(seq: list) -> dict: + + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + + return {value: key for key, value in d.items()} diff --git "a/Week04/decorators_ibrahim_\303\266zel.py" "b/Week04/decorators_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..e6cee147 --- /dev/null +++ "b/Week04/decorators_ibrahim_\303\266zel.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 diff --git "a/Week04/functions_ibrahim_\303\266zel.py" "b/Week04/functions_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..16bf3bc1 --- /dev/null +++ "b/Week04/functions_ibrahim_\303\266zel.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: + """ + This function does arithmetic opearations. + + :param1: first number to be exponantiated + :param2: second number to be exponantiated + :param3: power of the first number + :param4: power of the second number + :param5: divisor of sum of exponantiated numbers + + :return: division the sum of exponantiated numbers + """ + return (x**a + y**b) / c + +call_counter = 0 +caller_dict = {} +def fn_w_counter() -> (int, dict[str, int]): + caller = __name__ + global call_counter + call_counter += 1 + if caller in caller_dict: + caller_dict[caller] += 1 + else: + caller_dict[caller] = 1 + return call_counter, caller_dict diff --git "a/Week05/emails_ibrahim_\303\266zel.py" "b/Week05/emails_ibrahim_\303\266zel.py" new file mode 100644 index 00000000..37bbcc49 --- /dev/null +++ "b/Week05/emails_ibrahim_\303\266zel.py" @@ -0,0 +1,30 @@ +class Emails(list): + def __init__(self, email_list): + checked = self.validate(email_list) + super().__init__(checked) + self.data = checked + + def validate(self, email_list): + result = [] + for item in email_list: + if type(item) is not str: + raise ValueError("Only strings are allowed") + if item.count("@") != 1: + raise ValueError("Invalid email: " + item) + user, domain = item.split("@") + if user == "" or "." not in domain: + raise ValueError("Invalid email: " + item) + if domain.startswith(".") or domain.endswith("."): + raise ValueError("Invalid email: " + item) + if item not in result: + result.append(item) + return result + + def __repr__(self): + return "Emails(" + str(list(self)) + ")" + + def __str__(self): + text = "Emails:\n" + for i, mail in enumerate(self, start=1): + text += f"{i}. {mail}\n" + return text