From 83e52f5c90cb5b4a593644d0d97e892bc40be58d Mon Sep 17 00:00:00 2001 From: Anuj Soni Date: Mon, 13 Oct 2025 15:06:55 +0530 Subject: [PATCH 1/3] feat: add pattern printing (pyramid, inverted pyramid, diamond) [#13460] --- other/pyramid_patterns.py | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 other/pyramid_patterns.py diff --git a/other/pyramid_patterns.py b/other/pyramid_patterns.py new file mode 100644 index 000000000000..d140eb802451 --- /dev/null +++ b/other/pyramid_patterns.py @@ -0,0 +1,57 @@ +""" +patterns/pyramid_patterns.py + +Pattern Printing Examples: +- Pyramid +- Inverted Pyramid +- Diamond + +Demonstrates loops, functions, and conditionals for beginners. + +Example: +>>> pyramid(3) + * + *** +***** + +>>> inverted_pyramid(3) +***** + *** + * + +>>> diamond(3) + * + *** +***** + *** + * +""" + +# No import needed for None type annotation + +def pyramid(n: int) -> None: + """Prints a pyramid pattern of height n.""" + for i in range(n): + print(" " * (n - i - 1) + "*" * (2 * i + 1)) + + +def inverted_pyramid(n: int) -> None: + """Prints an inverted pyramid pattern of height n.""" + for i in range(n - 1, -1, -1): + print(" " * (n - i - 1) + "*" * (2 * i + 1)) + + +def diamond(n: int) -> None: + """Prints a diamond pattern of height n.""" + pyramid(n) + for i in range(n - 2, -1, -1): + print(" " * (n - i - 1) + "*" * (2 * i + 1)) + + +if __name__ == "__main__": + print("Pyramid:") + pyramid(5) + print("\nInverted Pyramid:") + inverted_pyramid(5) + print("\nDiamond:") + diamond(5) From 5ad69594107dc98bf6943b61d11332c5571c4d1b Mon Sep 17 00:00:00 2001 From: Anuj Soni Date: Tue, 21 Oct 2025 23:07:58 +0530 Subject: [PATCH 2/3] Use descriptive parameter names in pyramid patterns - Replace generic parameter 'n' with descriptive 'height' - Update all function signatures and docstrings - Maintain functionality while improving code readability - All ruff checks pass --- other/pyramid_patterns.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/other/pyramid_patterns.py b/other/pyramid_patterns.py index d140eb802451..26fea9b3acd0 100644 --- a/other/pyramid_patterns.py +++ b/other/pyramid_patterns.py @@ -29,23 +29,23 @@ # No import needed for None type annotation -def pyramid(n: int) -> None: - """Prints a pyramid pattern of height n.""" - for i in range(n): - print(" " * (n - i - 1) + "*" * (2 * i + 1)) +def pyramid(height: int) -> None: + """Prints a pyramid pattern of the specified height.""" + for i in range(height): + print(" " * (height - i - 1) + "*" * (2 * i + 1)) -def inverted_pyramid(n: int) -> None: - """Prints an inverted pyramid pattern of height n.""" - for i in range(n - 1, -1, -1): - print(" " * (n - i - 1) + "*" * (2 * i + 1)) +def inverted_pyramid(height: int) -> None: + """Prints an inverted pyramid pattern of the specified height.""" + for i in range(height - 1, -1, -1): + print(" " * (height - i - 1) + "*" * (2 * i + 1)) -def diamond(n: int) -> None: - """Prints a diamond pattern of height n.""" - pyramid(n) - for i in range(n - 2, -1, -1): - print(" " * (n - i - 1) + "*" * (2 * i + 1)) +def diamond(height: int) -> None: + """Prints a diamond pattern of the specified height.""" + pyramid(height) + for i in range(height - 2, -1, -1): + print(" " * (height - i - 1) + "*" * (2 * i + 1)) if __name__ == "__main__": From 8a95ebe81f0d1e1881c83fbfb0d8fe48876557c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Oct 2025 17:40:29 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/pyramid_patterns.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/pyramid_patterns.py b/other/pyramid_patterns.py index 26fea9b3acd0..6331aa5bbfe9 100644 --- a/other/pyramid_patterns.py +++ b/other/pyramid_patterns.py @@ -29,6 +29,7 @@ # No import needed for None type annotation + def pyramid(height: int) -> None: """Prints a pyramid pattern of the specified height.""" for i in range(height):