From 255584176286bb6c589c02aa232ab8de76d52972 Mon Sep 17 00:00:00 2001 From: Saurabh Gupta Date: Tue, 28 Oct 2025 14:39:02 +0530 Subject: [PATCH 1/2] Add program to create a pyramid of stars Program to create a pyramid of stars. --- Pyramid of stars | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Pyramid of stars diff --git a/Pyramid of stars b/Pyramid of stars new file mode 100644 index 0000000000..0220b87ef8 --- /dev/null +++ b/Pyramid of stars @@ -0,0 +1,13 @@ +# Program to create a pyramid of stars + +rows = int(input("Enter the number of rows: ")) + +for i in range(1, rows + 1): + for spaces in range(1, rows - i + 1): + print(end=' ') + + for stars in range(1, i + 1): + print('*', end=' ') + + print() + From b5d4ccc024939a076526f66a6022b9846dbce9e4 Mon Sep 17 00:00:00 2001 From: Saurabh Gupta Date: Tue, 28 Oct 2025 16:36:29 +0530 Subject: [PATCH 2/2] Added pyramid_of_stars.py script --- pyramid_of_stars.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pyramid_of_stars.py diff --git a/pyramid_of_stars.py b/pyramid_of_stars.py new file mode 100644 index 0000000000..6967dafc02 --- /dev/null +++ b/pyramid_of_stars.py @@ -0,0 +1,31 @@ +# Program to print a centered full pyramid of stars based on user input + +def get_positive_int(prompt: str) -> int: + """Prompt the user until they provide a positive integer (> 0).""" + while True: + try: + value = int(input(prompt).strip()) + if value <= 0: + print("Please enter a positive integer greater than zero.") + continue + return value + except ValueError: + print("Invalid input. Please enter a valid integer.") + + +def draw_pyramid(rows: int) -> None: + """Print a centered full pyramid of stars with the given number of rows.""" + for i in range(1, rows + 1): + spaces = ' ' * (rows - i) + stars = '* ' * i + # rstrip to avoid trailing space at line end + print(f"{spaces}{stars.rstrip()}") + + +def main() -> None: + rows = get_positive_int("Enter the number of rows: ") + draw_pyramid(rows) + + +if __name__ == "__main__": + main()