Skip to content

Commit b3b50a0

Browse files
authored
Merge branch 'canbula:master' into master
2 parents 7d7eb95 + 8cfff6e commit b3b50a0

12 files changed

Lines changed: 232 additions & 0 deletions

‎Week02/types_ahmet_murat_akarsu.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my_int = 12
2+
my_float = 3.45
3+
my_bool = True
4+
my_complex = 6 + 7j

‎Week02/types_yasin_buyuktepe.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
my_int = 42
2+
my_float = 3.14
3+
my_bool = True
4+
my_complex = 2 + 3j
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def calculate_pyramid_height(number_of_blocks: int) -> int:
2+
height = 0 # Güncel height
3+
needed_blocks = 1 # o anki katmanda gereken blok sayısı
4+
while number_of_blocks >= needed_blocks:
5+
number_of_blocks -= needed_blocks
6+
height += 1
7+
needed_blocks += 1
8+
return height

‎Week03/pyramid_yasin_buyuktepe.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0
3+
while number_of_blocks >= height + 1:
4+
height += 1
5+
number_of_blocks -= height
6+
return height
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def remove_duplicates(seq: list) -> list:
2+
result = []
3+
for item in seq:
4+
if item not in result:
5+
result.append(item)
6+
return result
7+
8+
def list_counts(seq: list) -> dict:
9+
counts = {}
10+
for item in seq:
11+
counts[item] = counts.get(item, 0) + 1
12+
return counts
13+
14+
def reverse_dict(d: dict) -> dict:
15+
return {v: k for k, v in d.items()}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
unique = []
6+
for item in seq:
7+
if item not in unique:
8+
unique.append(item)
9+
return unique
10+
11+
12+
def list_counts(seq: list) -> dict:
13+
"""
14+
This function counts the number of occurrences of each item in a list.
15+
"""
16+
counts = {}
17+
for item in seq:
18+
counts[item] = counts.get(item, 0) + 1
19+
return counts
20+
21+
22+
def reverse_dict(d: dict) -> dict:
23+
"""
24+
This function reverses the keys and values of a dictionary.
25+
"""
26+
return {value: key for key, value in d.items()}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import time
2+
import tracemalloc
3+
4+
def performance(f):
5+
if not hasattr(performance, "counter"):
6+
performance.counter = 0
7+
if not hasattr(performance, "total_time"):
8+
performance.total_time = 0.0
9+
if not hasattr(performance, "total_mem"):
10+
performance.total_mem = 0
11+
12+
def _performance(*args, **kwargs):
13+
# Çağırılma sayısı
14+
performance.counter += 1
15+
16+
# Takip başlat
17+
tracemalloc.start()
18+
x = time.time()
19+
20+
# Fonksiyonu çağır
21+
ret = f(*args, **kwargs)
22+
23+
# süreyi kaydet
24+
performance.total_time += time.time() - x
25+
# bellek tüketimini kaydet
26+
performance.total_mem = tracemalloc.get_traced_memory()[1]
27+
# takibi bırak
28+
tracemalloc.stop()
29+
30+
return ret
31+
return _performance
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import time
2+
import tracemalloc
3+
4+
5+
def performance(func):
6+
def wrapper(*args, **kwargs):
7+
tracemalloc.start()
8+
start = time.perf_counter()
9+
try:
10+
return func(*args, **kwargs)
11+
finally:
12+
elapsed = time.perf_counter() - start
13+
_, peak = tracemalloc.get_traced_memory()
14+
tracemalloc.stop()
15+
performance.counter += 1
16+
performance.total_time += elapsed
17+
performance.total_mem += peak
18+
return wrapper
19+
20+
21+
performance.counter = 0
22+
performance.total_time = 0
23+
performance.total_mem = 0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
"""Calculate custom polynomial equation result.
5+
6+
Calculates :math:`\\frac{x^a + y^b}{c}`.
7+
8+
:param x: Positional-only x value, defaults to 0
9+
:type x: int, optional
10+
:param y: Positional-only y value, defaults to 0
11+
:type y: int, optional
12+
:param a: Positional-or-keyword exponent for x, defaults to 1
13+
:type a: int, optional
14+
:param b: Positional-or-keyword exponent for y, defaults to 1
15+
:type b: int, optional
16+
:param c: Keyword-only denominator, defaults to 1
17+
:type c: int, optional
18+
:return: Result of (x**a + y**b) / c
19+
:rtype: float
20+
"""
21+
return (x**a + y**b) / c
22+
23+
def fn_w_counter() -> (int, dict[str, int]):
24+
if not hasattr(fn_w_counter, "counter"):
25+
fn_w_counter.counter = 0
26+
fn_w_counter.counter += 1
27+
return (fn_w_counter.counter, {fn_w_counter.__module__: fn_w_counter.counter})
28+
if __name__ == "__main__":
29+
print(fn_w_counter())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
custom_power = lambda x=0, /, e=1: x ** e
3+
4+
5+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
6+
"""
7+
Calculates (x**a + y**b) / c.
8+
9+
:param x: First base, positional-only
10+
:param y: Second base, positional-only
11+
:param a: Exponent of x
12+
:param b: Exponent of y
13+
:param c: Divisor, keyword-only
14+
:return: Result of (x**a + y**b) / c
15+
"""
16+
return (x ** a + y ** b) / c
17+
18+
19+
_total_calls = 0
20+
_callers = {}
21+
22+
23+
def fn_w_counter() -> (int, dict[str, int]):
24+
global _total_calls
25+
caller = __name__
26+
_total_calls += 1
27+
_callers[caller] = _callers.get(caller, 0) + 1
28+
return _total_calls, _callers

0 commit comments

Comments
 (0)