Skip to content
Closed
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_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def calculate_pyramid_height(number_of_blocks):
height = 0
while(number_of_blocks >= 0):
height += 1
number_of_blocks -= height
return height - 1

23 changes: 23 additions & 0 deletions Week03/sequences_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def remove_duplicates(seq):
result = []
for item in seq:
if item not in result:
result.append(item)
return result


def list_counts(seq):
counts = {}
for item in seq:
if item in counts:
counts[item] += 1
else:
counts[item] = 1
return counts


def reverse_dict(d):
reversed_dict = {}
for key, value in d.items():
reversed_dict[value] = key
return reversed_dict
21 changes: 21 additions & 0 deletions Week04/decorators_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time
import tracemalloc

def performance(func):
func.counter = 0
func.total_time = 0
func.total_mem = 0

def wrapper(*args, **kwargs):
func.counter += 1
start_time = time.perf_counter()
tracemalloc.start()
result = func(*args, **kwargs)
current, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
func.total_time += (time.perf_counter() - start_time)
func.total_mem += peak

return result

return wrapper
21 changes: 21 additions & 0 deletions Week04/functions_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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:
"""
Calculate a custom equation: (x**a + y**b) / c

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

def fn_w_counter(_calls={"__main__": 0}):
_calls["__main__"] += 1
return _calls["__main__"], dict(_calls)


Loading