Skip to content

Commit ed043c9

Browse files
authored
Merge pull request #581 from FurkanBaytak/master
Furkan Baytak - W1, W4, W5, W6 Homeworks
2 parents 8deae8c + 0ea6d8c commit ed043c9

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

Week01/info_furkan_baytak.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
student_id = "210316033"
2+
full_name = "Furkan Baytak"

Week04/decorators_furkan_baytak.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import sys
3+
4+
def performance(func):
5+
6+
if not hasattr(performance, 'counter'):
7+
setattr(performance, 'counter', 0)
8+
9+
if not hasattr(performance, 'total_time'):
10+
setattr(performance, 'total_time', 0.0)
11+
12+
if not hasattr(performance, 'total_mem'):
13+
setattr(performance, 'total_mem', 0)
14+
15+
def wrapper(*args, **kwargs):
16+
start_time = time.time()
17+
memory_usage=sys.getsizeof(func(*args, **kwargs))
18+
end_time = time.time()
19+
20+
setattr(performance, 'counter', getattr(performance, 'counter') + 1)
21+
setattr(performance, 'total_time', getattr(performance, 'total_time') + (end_time - start_time))
22+
setattr(performance, 'total_mem', getattr(performance, 'total_mem') + memory_usage)
23+
24+
return func(*args, **kwargs)
25+
26+
return wrapper
27+

Week04/functions_furkan_baytak.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
custom_power = lambda x = 0, /, e = 1: x ** e
2+
3+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
4+
"""
5+
This function computes the result of the equation:
6+
7+
:param x: The positional-only integer base for the first term, default is 0
8+
:param y: The positional-only integer base for the second term, default is 0
9+
:param a: The positional-or-keyword integer exponent for the first term, default is 1
10+
:param b: The positional-or-keyword integer exponent for the second term, default is 1
11+
:param c: The keyword-only integer divisor, default is 1
12+
:return: The result of the calculation as a float
13+
:rtype: float
14+
"""
15+
return (x ** a + y ** b) / c
16+
17+
def fn_w_counter() -> (int, dict[str, int]):
18+
if not hasattr(fn_w_counter, "call_counter"):
19+
fn_w_counter.call_counter = 0
20+
fn_w_counter.caller_counts = {}
21+
22+
caller_name = __name__
23+
fn_w_counter.call_counter += 1
24+
25+
if caller_name in fn_w_counter.caller_counts:
26+
fn_w_counter.caller_counts[caller_name] += 1
27+
else:
28+
fn_w_counter.caller_counts[caller_name] = 1
29+
30+
return fn_w_counter.call_counter, fn_w_counter.caller_counts

Week05/awaitme_furkan_baytak.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import asyncio
2+
3+
def awaitme(func):
4+
async def _awaitme(*args, **kwargs):
5+
result = func(*args, **kwargs)
6+
if asyncio.iscoroutine(result):
7+
return await result
8+
return result
9+
return _awaitme

Week06/timer_furkan_baytak.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import pytest
3+
import time
4+
5+
class Timer:
6+
def __init__(self):
7+
print(f"Initializing {self.__class__.__name__}")
8+
9+
def __enter__(self) -> "Timer":
10+
print(f"Entering {self.__class__.__name__}")
11+
self.start_time = time.time()
12+
return self
13+
14+
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
15+
print(f"Exiting {self.__class__.__name__}")
16+
self.end_time = time.time()
17+
self.elapsed_time = self.end_time - self.start_time
18+
return True

0 commit comments

Comments
 (0)