diff --git a/Week03/pyramid_hasan_canli.py b/Week03/pyramid_hasan_canli.py new file mode 100644 index 00000000..498a2d12 --- /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] - )