From c4febc73c21753a8fc165faad5d36ccc0ff27f4c Mon Sep 17 00:00:00 2001 From: Hasan Date: Mon, 17 Nov 2025 21:59:02 +0300 Subject: [PATCH 1/2] Update and rename test_pyramid.py to pyramid_hasan_canli.py --- Week03/pyramid_hasan_canli.py | 13 +++++++++ Week03/test_pyramid.py | 52 ----------------------------------- 2 files changed, 13 insertions(+), 52 deletions(-) create mode 100644 Week03/pyramid_hasan_canli.py delete mode 100644 Week03/test_pyramid.py diff --git a/Week03/pyramid_hasan_canli.py b/Week03/pyramid_hasan_canli.py new file mode 100644 index 00000000..d096e9b2 --- /dev/null +++ b/Week03/pyramid_hasan_canli.py @@ -0,0 +1,13 @@ +def calculate_pyramid_height(number_of_blocks): + + height = 0 + blocks__for_next_layer = 1 + + while number_of_blocks >= blocks_for_next_layer: + + number_of_blocks -= blocks_for_next_layer + height += 1 + blocks_for_next_layer += 1 + + return height + diff --git a/Week03/test_pyramid.py b/Week03/test_pyramid.py deleted file mode 100644 index 2c8c6f25..00000000 --- a/Week03/test_pyramid.py +++ /dev/null @@ -1,52 +0,0 @@ -import os - - -files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("pyramid")] -for f in files: - exec("import " + f[:-3] + " as " + f[:-3]) - print(f"The module {f[:-3]} has been imported.") - - -def test_names(): - for f in files: - assert "calculate_pyramid_height" in dir(eval(f[:-3])), ( - "calculate_pyramid_height is not defined in " + f[:-3] - ) - - -def test_types(): - for f in files: - assert callable(eval(f[:-3]).calculate_pyramid_height), ( - "calculate_pyramid_height is not callable in " + f[:-3] - ) - assert isinstance(eval(f[:-3]).calculate_pyramid_height(1), int), ( - "calculate_pyramid_height is not returning an int in " + f[:-3] - ) - - -def test_calculate_pyramid_height(): - for f in files: - assert eval(f[:-3]).calculate_pyramid_height(1) == 1, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(2) == 1, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(6) == 3, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(20) == 5, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(100) == 13, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(1000) == 44, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(10000) == 140, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) - assert eval(f[:-3]).calculate_pyramid_height(100000) == 446, ( - "calculate_pyramid_height is not working in " + f[:-3] - ) From 9fbd10f2ed4009ae3ad1004d8c6bcf50b3186f0c Mon Sep 17 00:00:00 2001 From: Hasan Date: Mon, 17 Nov 2025 22:20:46 +0300 Subject: [PATCH 2/2] Update pyramid_hasan_canli.py --- Week03/pyramid_hasan_canli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week03/pyramid_hasan_canli.py b/Week03/pyramid_hasan_canli.py index d096e9b2..498a2d12 100644 --- a/Week03/pyramid_hasan_canli.py +++ b/Week03/pyramid_hasan_canli.py @@ -1,7 +1,7 @@ def calculate_pyramid_height(number_of_blocks): height = 0 - blocks__for_next_layer = 1 + blocks_for_next_layer = 1 while number_of_blocks >= blocks_for_next_layer: