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_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
student_id = "220316051"
full_name = "Umut Şahin"
4 changes: 4 additions & 0 deletions Week02/types_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 47
my_float = 2 / 1
my_bool = True
my_complex = 3j
10 changes: 10 additions & 0 deletions Week03/pyramid_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
n = 0
while True:
blocks_needed = (n * (n + 1)) // 2
if blocks_needed > number_of_blocks:
break
height = n
n += 1
return height
32 changes: 32 additions & 0 deletions Week04/decorators_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import tracemalloc, time

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.
"""
performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0.0

def wrapper(*args, **kwargs):
tracemalloc.start()
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
current, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
performance.counter += 1
performance.total_time += (end_time - start_time)
performance.total_mem += peak
return result

return wrapper
29 changes: 29 additions & 0 deletions Week04/functions_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 for the equation , default is 0
:param y: The positional-only integer base parameter for the equation , default is 0
:param a: The positional-or-keyword integer exponent parameter for the equation , default is 1
:param b: The positional-or-keyword integer exponent parameter for the equation , default is 1
:param c: The keyword-only integer divisor parameter for the equation , default is 1
:return: The result of the calculation as a float and the equation is (x**a + y**b) / c
:rtype: float
"""
return (x**a + y**b) / c


def fn_w_counter() -> (int, dict[str, int]):
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
9 changes: 9 additions & 0 deletions Week05/awaitme_umut_sahin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import asyncio

def awaitme(function):
async def wrapper(*args, **kwargs):
result = function(*args, **kwargs)
if asyncio.iscoroutine(result):
return await result
return result
return wrapper