From d2b05275094346caceff8afefea11b4409cad100 Mon Sep 17 00:00:00 2001 From: aydinomer00 <109145643+aydinomer00@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:09:33 +0300 Subject: [PATCH 01/11] Add butterfly pattern implementation --- graphics/butterfly_pattern.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 graphics/butterfly_pattern.py diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py new file mode 100644 index 000000000000..03b3a72bb53b --- /dev/null +++ b/graphics/butterfly_pattern.py @@ -0,0 +1,15 @@ +def butterfly_pattern(n): + # Üst kısım + for i in range(1, n + 1): + print("*" * i, end="") + print(" " * (2 * (n - i)), end="") + print("*" * i) + + # Alt kısım + for i in range(n-1, 0, -1): + print("*" * i, end="") + print(" " * (2 * (n - i)), end="") + print("*" * i) + +n = int(input("Enter the size: ")) +butterfly_pattern(n) \ No newline at end of file From d8a717920953520bd5fa3a5d304b0f34bd31a24b Mon Sep 17 00:00:00 2001 From: aydinomer00 <109145643+aydinomer00@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:11:09 +0300 Subject: [PATCH 02/11] Add butterfly pattern implementation --- graphics/butterfly_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 03b3a72bb53b..12e57c056648 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -1,11 +1,11 @@ def butterfly_pattern(n): - # Üst kısım + # Upper part for i in range(1, n + 1): print("*" * i, end="") print(" " * (2 * (n - i)), end="") print("*" * i) - # Alt kısım + # Lower part for i in range(n-1, 0, -1): print("*" * i, end="") print(" " * (2 * (n - i)), end="") From 459613ebd503a41a23c36d559320cb4ff4269144 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 19:13:34 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- graphics/butterfly_pattern.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 12e57c056648..6fd15b38b148 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -6,10 +6,11 @@ def butterfly_pattern(n): print("*" * i) # Lower part - for i in range(n-1, 0, -1): + for i in range(n - 1, 0, -1): print("*" * i, end="") print(" " * (2 * (n - i)), end="") print("*" * i) + n = int(input("Enter the size: ")) -butterfly_pattern(n) \ No newline at end of file +butterfly_pattern(n) From f99e68ecd1c0faa80092e9156794671a7524b48b Mon Sep 17 00:00:00 2001 From: aydinomer00 <109145643+aydinomer00@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:51:18 +0300 Subject: [PATCH 04/11] Add finalized butterfly pattern implementation and test --- graphics/butterfly_pattern.py | 29 ++++++++++++++++++++--------- graphics/test_butterfly_pattern.py | 11 +++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 graphics/test_butterfly_pattern.py diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 6fd15b38b148..bbc5519e00bf 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -1,16 +1,27 @@ -def butterfly_pattern(n): +def butterfly_pattern(n: int) -> str: + """ + Creates a butterfly pattern of size n and returns it as a string. + """ + result = [] + # Upper part for i in range(1, n + 1): - print("*" * i, end="") - print(" " * (2 * (n - i)), end="") - print("*" * i) + left_stars = "*" * i + spaces = " " * (2 * (n - i + 2)) + right_stars = "*" * i + result.append(left_stars + spaces + right_stars) # Lower part for i in range(n - 1, 0, -1): - print("*" * i, end="") - print(" " * (2 * (n - i)), end="") - print("*" * i) + left_stars = "*" * i + spaces = " " * (2 * (n - i + 2)) + right_stars = "*" * i + result.append(left_stars + spaces + right_stars) + + return "\n".join(result) + +if __name__ == "__main__": + n = int(input("Enter the size of the butterfly pattern: ")) + print(butterfly_pattern(n)) -n = int(input("Enter the size: ")) -butterfly_pattern(n) diff --git a/graphics/test_butterfly_pattern.py b/graphics/test_butterfly_pattern.py new file mode 100644 index 000000000000..9630b73ca397 --- /dev/null +++ b/graphics/test_butterfly_pattern.py @@ -0,0 +1,11 @@ +from graphics.butterfly_pattern import butterfly_pattern + +def test_butterfly_pattern(): + expected_output = ( + "* *\n" + "** **\n" + "*** ***\n" + "** **\n" + "* *" + ) + assert butterfly_pattern(3) == expected_output From 00e2985cfd7d2c92e22f869831810185293ec5b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:51:47 +0000 Subject: [PATCH 05/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- graphics/butterfly_pattern.py | 1 - graphics/test_butterfly_pattern.py | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index bbc5519e00bf..a55fa79f5b04 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -24,4 +24,3 @@ def butterfly_pattern(n: int) -> str: if __name__ == "__main__": n = int(input("Enter the size of the butterfly pattern: ")) print(butterfly_pattern(n)) - diff --git a/graphics/test_butterfly_pattern.py b/graphics/test_butterfly_pattern.py index 9630b73ca397..c509ba978e61 100644 --- a/graphics/test_butterfly_pattern.py +++ b/graphics/test_butterfly_pattern.py @@ -1,11 +1,8 @@ from graphics.butterfly_pattern import butterfly_pattern + def test_butterfly_pattern(): expected_output = ( - "* *\n" - "** **\n" - "*** ***\n" - "** **\n" - "* *" + "* *\n" "** **\n" "*** ***\n" "** **\n" "* *" ) assert butterfly_pattern(3) == expected_output From de046d25ecc742d1c11d113d6760374ff7c30d47 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Tue, 14 Jan 2025 23:52:25 +0300 Subject: [PATCH 06/11] Delete graphics/test_butterfly_pattern.py --- graphics/test_butterfly_pattern.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 graphics/test_butterfly_pattern.py diff --git a/graphics/test_butterfly_pattern.py b/graphics/test_butterfly_pattern.py deleted file mode 100644 index c509ba978e61..000000000000 --- a/graphics/test_butterfly_pattern.py +++ /dev/null @@ -1,8 +0,0 @@ -from graphics.butterfly_pattern import butterfly_pattern - - -def test_butterfly_pattern(): - expected_output = ( - "* *\n" "** **\n" "*** ***\n" "** **\n" "* *" - ) - assert butterfly_pattern(3) == expected_output From a7ffc5c49dc949c998410c30af7af29141d4b4d5 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Tue, 14 Jan 2025 23:59:09 +0300 Subject: [PATCH 07/11] Update butterfly_pattern.py --- graphics/butterfly_pattern.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index a55fa79f5b04..55dd8014ff4e 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -1,6 +1,13 @@ def butterfly_pattern(n: int) -> str: """ Creates a butterfly pattern of size n and returns it as a string. + + >>> butterfly_pattern(3) + * * + ** ** + ***** + ** ** + * * """ result = [] From ad7f05414ac547f6b1b2b78c046602087eb7ea5d Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 15 Jan 2025 00:01:51 +0300 Subject: [PATCH 08/11] Update butterfly_pattern.py --- graphics/butterfly_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 55dd8014ff4e..109a8b22e8aa 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -2,7 +2,7 @@ def butterfly_pattern(n: int) -> str: """ Creates a butterfly pattern of size n and returns it as a string. - >>> butterfly_pattern(3) + >>> print(butterfly_pattern(3)) * * ** ** ***** From 391e66462e605ddc5f25178b06b830e69fb194e9 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 15 Jan 2025 00:04:18 +0300 Subject: [PATCH 09/11] Update butterfly_pattern.py --- graphics/butterfly_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 109a8b22e8aa..7ee10a16ba23 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -14,14 +14,14 @@ def butterfly_pattern(n: int) -> str: # Upper part for i in range(1, n + 1): left_stars = "*" * i - spaces = " " * (2 * (n - i + 2)) + spaces = " " * (2 * (n - i)) right_stars = "*" * i result.append(left_stars + spaces + right_stars) # Lower part for i in range(n - 1, 0, -1): left_stars = "*" * i - spaces = " " * (2 * (n - i + 2)) + spaces = " " * (2 * (n - i)) right_stars = "*" * i result.append(left_stars + spaces + right_stars) From 186806c22eb73d126bc8158f3a14c0b3a10caaf4 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 15 Jan 2025 00:08:41 +0300 Subject: [PATCH 10/11] Update butterfly_pattern.py --- graphics/butterfly_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 7ee10a16ba23..955bc3cd0d9b 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -14,14 +14,14 @@ def butterfly_pattern(n: int) -> str: # Upper part for i in range(1, n + 1): left_stars = "*" * i - spaces = " " * (2 * (n - i)) + spaces = " " * (2 * (n - i) - 1) right_stars = "*" * i result.append(left_stars + spaces + right_stars) # Lower part for i in range(n - 1, 0, -1): left_stars = "*" * i - spaces = " " * (2 * (n - i)) + spaces = " " * (2 * (n - i) - 1) right_stars = "*" * i result.append(left_stars + spaces + right_stars) From f00a5f7673ee4f39da969116928517bb7ce04ae1 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 15 Jan 2025 00:21:42 +0300 Subject: [PATCH 11/11] Update butterfly_pattern.py --- graphics/butterfly_pattern.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/graphics/butterfly_pattern.py b/graphics/butterfly_pattern.py index 955bc3cd0d9b..7913b03a7e95 100644 --- a/graphics/butterfly_pattern.py +++ b/graphics/butterfly_pattern.py @@ -8,16 +8,29 @@ def butterfly_pattern(n: int) -> str: ***** ** ** * * + >>> print(butterfly_pattern(5)) + * * + ** ** + *** *** + **** **** + ********* + **** **** + *** *** + ** ** + * * """ result = [] # Upper part - for i in range(1, n + 1): + for i in range(1, n): left_stars = "*" * i spaces = " " * (2 * (n - i) - 1) right_stars = "*" * i result.append(left_stars + spaces + right_stars) + # Middle part + result.append("*" * (2 * n - 1)) + # Lower part for i in range(n - 1, 0, -1): left_stars = "*" * i