Skip to content

Commit 1200eed

Browse files
All assignments completed between weeks 2 and 5
1 parent 8eb313a commit 1200eed

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed

Week02/types_furkan_cetiner.py

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

Week03/pyramid_furkan_cetiner.py

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

Week03/sequences_furkan_cetiner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def remove_duplicates(seq: list) -> list:
2+
3+
result = []
4+
for item in seq:
5+
if item not in result:
6+
result.append(item)
7+
return result
8+
9+
10+
def list_counts(seq: list) -> dict:
11+
12+
counts = {}
13+
for item in seq:
14+
if item in counts:
15+
counts[item] += 1
16+
else:
17+
counts[item] = 1
18+
return counts
19+
20+
21+
def reverse_dict(d: dict) -> dict:
22+
23+
reversed_dict = {}
24+
for key, value in d.items():
25+
reversed_dict[value] = key
26+
return reversed_dict
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
import tracemalloc
3+
import functools
4+
5+
def performance(func):
6+
"""
7+
Fonksiyonun performansını ölçen ve istatistiklerini saklayan dekoratör.
8+
"""
9+
if not hasattr(performance, "counter"):
10+
performance.counter = 0
11+
performance.total_time = 0.0
12+
performance.total_mem = 0
13+
14+
@functools.wraps(func)
15+
def wrapper(*args, **kwargs):
16+
tracemalloc.start()
17+
start_time = time.perf_counter()
18+
result = func(*args, **kwargs)
19+
end_time = time.perf_counter()
20+
21+
current_mem, peak_mem = tracemalloc.get_traced_memory()
22+
tracemalloc.stop()
23+
24+
performance.counter += 1
25+
performance.total_time += (end_time - start_time)
26+
performance.total_mem += peak_mem
27+
28+
return result
29+
30+
return wrapper
31+
32+
performance.counter = 0
33+
performance.total_time = 0.0
34+
performance.total_mem = 0

Week04/functions_furkan_cetiner.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import inspect
2+
3+
# 1. custom_power: lambda function with positional-only x
4+
custom_power = lambda x=0, /, e=1: x**e
5+
6+
# 2. custom_equation: positional-only, positional-or-keyword, and keyword-only params
7+
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
8+
"""
9+
Calculates (x**a + y**b) / c with specific parameter constraints.
10+
:param x: Base 1, positional-only
11+
:param y: Base 2, positional-only
12+
:param a: Exponent 1, positional-or-keyword
13+
:param b: Exponent 2, positional-or-keyword
14+
:param c: Divisor, keyword-only
15+
:returns: Result as float
16+
"""
17+
return float((x**a + y**b) / c)
18+
19+
# 3. fn_w_counter: tracks total calls and caller names
20+
def fn_w_counter() -> tuple[int, dict]:
21+
"""
22+
Counts the number of calls and tracks the caller (__name__).
23+
"""
24+
if not hasattr(fn_w_counter, "calls"):
25+
fn_w_counter.calls = 0
26+
fn_w_counter.callers = {}
27+
28+
caller_frame = inspect.currentframe().f_back
29+
caller_name = caller_frame.f_globals.get('__name__', 'unknown')
30+
31+
fn_w_counter.calls += 1
32+
fn_w_counter.callers[caller_name] = fn_w_counter.callers.get(caller_name, 0) + 1
33+
34+
return (fn_w_counter.calls, fn_w_counter.callers)

Week05/emails_furkan_cetiner.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import re
2+
3+
class Emails(list):
4+
"""
5+
Emails class that extends list and validates email addresses.
6+
"""
7+
def __init__(self, email_list):
8+
validated_data = self.validate(email_list)
9+
super().__init__(validated_data)
10+
self.data = list(validated_data)
11+
12+
@staticmethod
13+
def validate(email_list):
14+
"""
15+
Validates that all items are strings and follow email format.
16+
Removes duplicates while preserving order (or just unique set).
17+
"""
18+
seen = []
19+
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
20+
21+
for email in email_list:
22+
if not isinstance(email, str):
23+
raise ValueError("All items must be strings.")
24+
25+
if not re.match(email_regex, email):
26+
raise ValueError(f"Invalid email format: {email}")
27+
28+
if email not in seen:
29+
seen.append(email)
30+
31+
return seen
32+
33+
def __repr__(self):
34+
"""
35+
Returns a string representation that can recreate the object.
36+
"""
37+
return f"Emails({list(self)})"
38+
39+
def __str__(self):
40+
"""
41+
Returns a user-friendly string representation.
42+
"""
43+
return f"Email List: {list(self)}"

0 commit comments

Comments
 (0)