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
7 changes: 7 additions & 0 deletions Week03/pyramid_mehmet_hamza_ogretmis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
blocks = 0
while blocks + height < number_of_blocks:
height += 1
blocks += height
return height
34 changes: 34 additions & 0 deletions Week03/sequences_mehmet_hamza_ogretmis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def remove_duplicates(seq: list) -> list:
"""
This function removes duplicates from a list
"""
result = []
for item in seq:
if item not in result:
result.append(item)
return result


def list_counts(seq: list) -> dict:
"""
This function counts the number of occurences
of each item in a list
"""
counts = {}
for item in seq:
if item in counts:
counts[item] += 1
else:
counts[item] = 1
return counts


def reverse_dict(d: dict) -> dict:
"""
This function reverses the keys and values
of a dictionary
"""
new_d = {}
for key, value in d.items():
new_d[value] = key
return new_d
29 changes: 29 additions & 0 deletions Week04/decorators_mehmet_hamza_ogretmis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import time
import tracemalloc


def performance(func):
"""Measure the time and memory each call of func takes and keep running totals."""

def wrapper(*args, **kwargs):
tracemalloc.start()
start = time.perf_counter()

result = func(*args, **kwargs)

elapsed = time.perf_counter() - start
_, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()

performance.counter += 1
performance.total_time += elapsed
performance.total_mem += peak

return result

return wrapper


performance.counter = 0
performance.total_time = 0
performance.total_mem = 0
32 changes: 32 additions & 0 deletions Week04/functions_mehmet_hamza_ogretmis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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:
"""
Compute (x**a + y**b) / c.

:param x: First base, positional-only
:type x: int
:param y: Second base, positional-only
:type y: int
:param a: Exponent of x
:type a: int
:param b: Exponent of y
:type b: int
:param c: Divisor, keyword-only
:type c: int
:return: The result of (x**a + y**b) / c
:rtype: float
"""
return (x ** a + y ** b) / c


def fn_w_counter() -> (int, dict[str, int]):
fn_w_counter.total += 1
fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1

return fn_w_counter.total, dict(fn_w_counter.callers)


fn_w_counter.total = 0
fn_w_counter.callers = {}
Loading