Skip to content

Commit 4184b2e

Browse files
authored
Merge pull request #766 from bugraozturk012/master
Homework
2 parents 3c271be + d4f4cdd commit 4184b2e

5 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎Week02/types_bugra_ozturk.py‎

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

‎Week03/pyramid_bugra_ozturk.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
height = 0
3+
used_blocks = 0
4+
while used_blocks + (height + 1) <= number_of_blocks:
5+
height += 1
6+
used_blocks += height
7+
return height

‎Week03/sequences_bugra_ozturk.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
result = []
6+
for item in seq:
7+
if item not in result:
8+
result.append(item)
9+
return result
10+
11+
12+
def list_counts(seq: list) -> dict:
13+
"""
14+
This function counts the number of
15+
occurrences of each item in a list.
16+
"""
17+
counts = {}
18+
for item in seq:
19+
counts[item] = counts.get(item, 0) + 1
20+
return counts
21+
22+
23+
def reverse_dict(d: dict) -> dict:
24+
"""
25+
This function reverses the keys
26+
and values of a dictionary.
27+
"""
28+
return {value: key for key, value in d.items()}

‎Week04/decorators_bugra_ozturk.py‎

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 _performance(*args, **kwargs):
7+
tracemalloc.start()
8+
start = time.perf_counter()
9+
result = func(*args, **kwargs)
10+
end = time.perf_counter()
11+
_, peak = tracemalloc.get_traced_memory()
12+
tracemalloc.stop()
13+
14+
performance.counter += 1
15+
performance.total_time += end - start
16+
performance.total_mem += peak
17+
return result
18+
return _performance
19+
20+
21+
performance.counter = 0
22+
performance.total_time = 0
23+
performance.total_mem = 0

‎Week04/functions_bugra_ozturk.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
custom_power = lambda x=0, /, e=1: x ** e
2+
3+
4+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
5+
"""
6+
Calculates the result of the equation (x**a + y**b) / c.
7+
8+
:param x: First base, positional-only
9+
:param y: Second base, positional-only
10+
:param a: Exponent of x
11+
:param b: Exponent of y
12+
:param c: Divisor, keyword-only
13+
:return: Result of (x**a + y**b) / c as a float
14+
"""
15+
for name, value in (("x", x), ("y", y), ("a", a), ("b", b), ("c", c)):
16+
if not isinstance(value, int):
17+
raise TypeError(f"{name} must be an integer")
18+
return (x ** a + y ** b) / c
19+
20+
21+
def fn_w_counter() -> (int, dict[str, int]):
22+
if not hasattr(fn_w_counter, "total"):
23+
fn_w_counter.total = 0
24+
fn_w_counter.callers = {}
25+
fn_w_counter.total += 1
26+
fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1
27+
return fn_w_counter.total, fn_w_counter.callers

0 commit comments

Comments
 (0)