- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
Added Pyramid of Stars Python Script #3256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Program to create a pyramid of stars.
| Reviewer's GuideAdds a new pyramid_of_stars.py script that interactively builds and prints a centered star pyramid using modular functions for input validation and pattern generation. Class diagram for pyramid_of_stars.py functionsclassDiagram
    class get_positive_int {
        +int get_positive_int(prompt: str)
        "Prompt user for positive integer input"
    }
    class draw_pyramid {
        +void draw_pyramid(rows: int)
        "Print centered pyramid of stars"
    }
    class main {
        +void main()
        "Entry point: gets input and draws pyramid"
    }
    main --> get_positive_int
    main --> draw_pyramid
File-Level Changes
 Tips and commandsInteracting with Sourcery
 Customizing Your ExperienceAccess your dashboard to: 
 Getting Help
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider simplifying the star generation by using '' * (2 * i - 1) for each row instead of ' ' * i and rstrip to avoid trailing spaces more directly.
- For greater flexibility and ease of automation, consider adding an optional command-line argument (via argparse) for the number of rows instead of relying solely on interactive input.
- The diff shows an unintended duplicate entry (“Pyramid of stars”) after the main script – please remove or correct it so only the intended .py file is added.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider simplifying the star generation by using '*' * (2 * i - 1) for each row instead of '* ' * i and rstrip to avoid trailing spaces more directly.
- For greater flexibility and ease of automation, consider adding an optional command-line argument (via argparse) for the number of rows instead of relying solely on interactive input.
- The diff shows an unintended duplicate entry (“Pyramid of stars”) after the main script – please remove or correct it so only the intended .py file is added.
## Individual Comments
### Comment 1
<location> `pyramid_of_stars.py:5-13` </location>
<code_context>
+
+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.")
+
+
</code_context>
<issue_to_address>
**suggestion:** Consider handling KeyboardInterrupt to allow graceful exit.
Currently, pressing Ctrl+C results in an unhandled exception. Catching KeyboardInterrupt would allow the program to exit cleanly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| 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.") | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider handling KeyboardInterrupt to allow graceful exit.
Currently, pressing Ctrl+C results in an unhandled exception. Catching KeyboardInterrupt would allow the program to exit cleanly.
This pull request introduces a new Python script named pyramid_of_stars.py that prints a beautiful pyramid pattern made of stars (*) based on user input.
The script is simple, interactive, and designed to demonstrate the fundamentals of loops, string formatting, and user input handling in Python.
It is a perfect beginner-friendly contribution for learning pattern generation and console output formatting.
🚀 Features
💻 Code Overview
The core logic uses:
🧠 Concepts Demonstrated
🧾 Example Output
Enter number of rows: 5
*
Thank you so much!
Summary by Sourcery
Introduce a new Python script to interactively generate a centered pyramid of stars based on user-specified rows
New Features: