Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Week01/info_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
student_id = "220316056"
full_name = "İbrahim Özel"
4 changes: 4 additions & 0 deletions Week02/types_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 32
my_float = 32.32
my_bool = True
my_complex = 3j2
6 changes: 6 additions & 0 deletions Week03/pyramid_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
while number_of_blocks >= height + 1:
height += 1
number_of_blocks -= height
return height
29 changes: 29 additions & 0 deletions Week03/sequences_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def remove_duplicates(seq: list) -> list:
"""
Removes duplicate elements from a list while preserving order.
"""
unique_items = []
for item in seq:
if item not in unique_items:
unique_items.append(item)
return unique_items


def list_counts(seq: list) -> dict:
"""
Counts the number of occurrences of each item in a list.
"""
counts = {}
for item in seq:
counts[item] = counts.get(item, 0) + 1
return counts


def reverse_dict(d: dict) -> dict:
"""
Reverses the keys and values of a dictionary.
"""
reversed_dict = {}
for key, value in d.items():
reversed_dict[value] = key
return reversed_dict
38 changes: 38 additions & 0 deletions Week04/decorators_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tracemalloc
import time
from functools import wraps


def performance(func):
"""
Decorator to track function performance and record statistics.

:param func: Function to decorate.
:type func: callable
:return: Wrapped function.
:rtype: callable

:cvar counter: Number of calls.
:cvar total_time: Total execution time in seconds.
:cvar total_mem: Total peak memory in bytes.
"""
@wraps(func)
def wrapper(*args, **kwargs):
tracemalloc.start()
start_time = time.perf_counter()
try:
result = func(*args, **kwargs)
return result
finally:
end_time = time.perf_counter()
current, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()

wrapper.counter += 1
wrapper.total_time += (end_time - start_time)
wrapper.total_mem += peak

wrapper.counter = 0
wrapper.total_time = 0.0
wrapper.total_mem = 0
return wrapper
37 changes: 37 additions & 0 deletions Week04/functions_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 raises x to the power of a, y to the power of b,
sums them, and then divides the result by c.

:param x: The positional-only integer base parameter
:param y: The positional-only integer base parameter
:param a: The exponent for x
:param b: The exponent for y
:param c: The divisor (keyword-only)
:return: (x**a + y**b) / c
:rtype: float
"""
return (x ** a + y ** b) / c


def fn_w_counter() -> tuple[int, dict[str, int]]:
"""
Counts how many times this function is called and records
how many calls came from each module.
"""
if not hasattr(fn_w_counter, '_call_counter'):
fn_w_counter._call_counter = 0
fn_w_counter._caller_dict = {}

caller = __name__
fn_w_counter._call_counter += 1

if caller in fn_w_counter._caller_dict:
fn_w_counter._caller_dict[caller] += 1
else:
fn_w_counter._caller_dict[caller] = 1

return fn_w_counter._call_counter, fn_w_counter._caller_dict
11 changes: 11 additions & 0 deletions Week05/awaitme_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import asyncio
from functools import wraps

def awaitme(function):
@wraps(function)
async def wrapper(*args, **kwargs):
result = function(*args, **kwargs)
if asyncio.iscoroutine(result):
return await result
return result
return wrapper
21 changes: 21 additions & 0 deletions Week06/timer_Ibrahim_Ozel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time


class Timer:
"""
A context manager class that measures the time taken
by the block of code it manages.
"""

def __init__(self):
self.start_time = None
self.end_time = None

def __enter__(self):
self.start_time = time.perf_counter()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.end_time = time.perf_counter()
print(f"Elapsed time: {self.end_time - self.start_time:.6f} seconds")
return False