Skip to content
Open

W2HW #659

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_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
my_int = 1312
my_float = 1157.25
my_bool = True
my_complex = 4j+8
11 changes: 11 additions & 0 deletions Week03/pyramid_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def calculate_pyramid_height(b_num):
a, b = 1, 0
while b < b_num:
b += a+1
a += 1


return a-1

if __name__ == "__main__":
print(calculate_pyramid_height(15))
39 changes: 39 additions & 0 deletions Week03/sequences_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def remove_duplicates(a_list):
my_list = a_list[:]
for i in a_list:
x = True
for j, k in enumerate(my_list):
if i == k:
if x:
x = False
else:
del my_list[j]
return my_list
def list_counts(a_list):
my_list = a_list[:]
a = remove_duplicates(my_list)
my_dict = dict.fromkeys(a)
for i in a:
x = 0
for j in a_list:
if i == j:
x += 1
my_dict[i] = x

return my_dict
def reverse_dict(a_dict):
my_dict = {}
a_list = list(a_dict)
b_list = list(a_dict.values())
x = 0
while x < len(a_list):
print(1)
my_dict[b_list[x]] = a_list[x]
x += 1

return my_dict

if __name__ == "__main__":
print(remove_duplicates([1,5,5,4,4,4,6,6,6,41,41,41,41,41,41,54,54,54,54,54,54,54,54,41,6]))
print(list_counts([1,5,5,4,4,4,6,6,6,41,41,41,41,41,54,54,54,54,54,54,54,54,41,6]))
print(reverse_dict(list_counts([1,5,5,4,4,4,6,6,6,41,41,41,41,41,54,54,54,54,54,54,54,54,41,6])))
26 changes: 26 additions & 0 deletions Week04/decorators_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time
import tracemalloc

def performance(f):
if not hasattr(performance, "counter"):
performance.counter = 0

if not hasattr(performance, "total_time"):
performance.total_time = 0.0

if not hasattr(performance, "total_mem"):
performance.total_mem = 0

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

tracemalloc.start()

x = time.time()

ret = f(*args, **kwargs)
performance.total_time += time.time() - x
performance.total_mem = tracemalloc.get_traced_memory()[1]
tracemalloc.stop()
return ret
return _performance
29 changes: 29 additions & 0 deletions Week04/functions_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 custom polynomial equation result.

Calculates :math:`\\frac{x^a + y^b}{c}`.

:param x: Positional-only x value, defaults to 0
:type x: int, optional
:param y: Positional-only y value, defaults to 0
:type y: int, optional
:param a: Positional-or-keyword exponent for x, defaults to 1
:type a: int, optional
:param b: Positional-or-keyword exponent for y, defaults to 1
:type b: int, optional
:param c: Keyword-only denominator, defaults to 1
:type c: int, optional
:return: Result of (x**a + y**b) / c
:rtype: float
"""
return (x**a + y**b) / c

def fn_w_counter() -> (int, dict[str, int]):
if not hasattr(fn_w_counter, "counter"):
fn_w_counter.counter = 0
fn_w_counter.counter += 1
return (fn_w_counter.counter, {fn_w_counter.__module__: fn_w_counter.counter})
if __name__ == "__main__":
print(fn_w_counter())
Loading