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
4 changes: 4 additions & 0 deletions Week02/types_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 230
my_float = 315.0
my_bool = True
my_complex = 12j
10 changes: 10 additions & 0 deletions Week03/pyramid_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def calculate_pyramid_height(blocks):
height = 0
blocks_needed = 1

while blocks >= blocks_needed:
blocks -= blocks_needed
height += 1
blocks_needed += 1

return height
19 changes: 19 additions & 0 deletions Week03/sequences_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def remove_duplicates(my_list):
return list(dict.fromkeys(my_list))


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


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

tracemalloc.start()


def performance(func):
def wrapper(*args, **kwargs):
performance.counter += 1

tracemalloc.reset_peak()
start_time = time.perf_counter()

result = func(*args, **kwargs)

end_time = time.perf_counter()
performance.total_time += (end_time - start_time)

_, peak = tracemalloc.get_traced_memory()
obj_size = sys.getsizeof(result)

performance.total_mem += max(peak, obj_size)

return result

return wrapper


performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0.0
32 changes: 32 additions & 0 deletions Week04/functions_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
custom_power = lambda x=0, /, e=1: float(x ** e)


def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
"""
Calculates (x**a + y**b) / c

:param x: base for the first term
:param y: base for the second term
:param a: exponent for the first term
:param b: exponent for the second term
:param c: divisor for the sum
:return: the result of the equation as float
"""
if type(x) is not int: raise TypeError("x must be int")
if type(y) is not int: raise TypeError("y must be int")
if type(a) is not int: raise TypeError("a must be int")
if type(b) is not int: raise TypeError("b must be int")
if type(c) is not int: raise TypeError("c must be int")
return float((x ** a + y ** b) / c)

_total = 0
_counts = {}


def fn_w_counter() -> (int, dict[str, int]):
global _total
_total += 1
caller = __name__
_counts[caller] = _counts.get(caller, 0) + 1

return _total, _counts
5 changes: 5 additions & 0 deletions Week05/awaitme_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def awaitme(func):
async def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper
13 changes: 13 additions & 0 deletions Week06/timer_ozgun_kasapoglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import time

class Timer:
def __init__(self):
self.start_time = 0.0
self.end_time = 0.0

def __enter__(self):
self.start_time = time.time()
return self

def __exit__(self, a, b, c):
self.end_time = time.time()
Loading