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_ridvan_şevki_karsli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
student_id = "220315095"
full_name = "Rıdvan Şevki Karslı"
4 changes: 4 additions & 0 deletions Week02/types_ridvan_sevki_karsli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 120
my_float = 120.0
my_bool = 36 == 36
my_complex = 5j
7 changes: 7 additions & 0 deletions Week03/pyramid_ridvan_sevki_karsli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def calculate_pyramid_height(blocks):
total = 0
for i in range(1, blocks + 1):
total += i
if total > blocks:
return i - 1
return i
26 changes: 26 additions & 0 deletions Week04/decorators_ridvan_sevki_karsli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import tracemalloc
import time


class PerformanceTracker:
def __init__(self, func):
self.func = func
self.calls = 0
self.total_time = 0
self.total_memory = 0

def __call__(self, *args, **kwargs):
tracemalloc.start()

start = time.time()
result = self.func(*args, **kwargs)
end = time.time()

_, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()

self.calls += 1
self.total_time += (end - start)
self.total_memory += peak

return result
36 changes: 36 additions & 0 deletions Week04/functions_rıdvan_sevki_karslı.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
custom_power = lambda x=0, /, e=1: pow(x, e)


def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
"""
Computes a custom equation.

:param x: First base (positional only)
:param y: Second base (positional only)
:param a: First exponent
:param b: Second exponent
:param c: Divisor (keyword only)
:return: The result of (x^a + y^b) / c
"""

params = {'x': x, 'y': y, 'a': a, 'b': b, 'c': c}

for param_name in params:
if type(params[param_name]) is not int:
raise TypeError(f"{param_name} must be an integer")

if c == 0:
raise ZeroDivisionError("Division by zero is not allowed")

result = (custom_power(x, a) + custom_power(y, b)) / c

return float(result)


def fn_w_counter() -> (int, dict[str, int]):
if not hasattr(fn_w_counter, "count"):
setattr(fn_w_counter, "count", 0)

setattr(fn_w_counter, "count", fn_w_counter.count + 1)

return fn_w_counter.count, {fn_w_counter.__name__: fn_w_counter.count}
8 changes: 8 additions & 0 deletions Week05/awaitme_ridvan_sevki_karsli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import inspect

def awaitme(func):
async def wrapper(*args, **kwargs):
if inspect.iscoroutinefunction(func):
return await func(*args, **kwargs)
return func(*args, **kwargs)
return wrapper