Python Program to Print Right-Angled Triangle Star Pattern

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.

🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.

▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube

Introduction

A right-angled triangle star pattern consists of stars (*) arranged in a triangular shape. This pattern is commonly used to practice loops in programming, where the number of stars increases in each row.

Problem Statement

Create a Python program that:

  • Accepts the number of rows for the triangle.
  • Prints a right-angled triangle star pattern.

Example:

  • Input: rows = 5
  • Output:
    *
    **
    ***
    ****
    *****
    

Solution Steps

  1. Input the Number of Rows: The user defines how many rows the triangle should have.
  2. Use a Loop: The outer loop controls the rows, and an inner part handles printing the stars.
  3. Display the Right-Angled Triangle: Print stars in increasing order for each row.

Python Program

# Step 1: Input the number of rows
rows = int(input("Enter the number of rows: "))

# Step 2: Outer loop for rows
for i in range(1, rows + 1):
    # Step 3: Print stars for the current row
    print("*" * i)

Explanation

Step 1: Input the Number of Rows

  • The program starts by asking the user to input the number of rows for the right-angled triangle.

Step 2: Outer Loop for Rows

  • The outer loop runs from 1 to rows. It controls how many rows are printed.

Step 3: Print Stars

  • The loop prints stars (*) in increasing order. In each iteration, the number of stars printed corresponds to the current row number i.

Output Example

For rows = 5, the output will be:

*
**
***
****
*****

For rows = 3, the output will be:

*
**
***

Conclusion

This Python program prints a right-angled triangle star pattern using a loop to control the number of stars printed in each row. This exercise is a simple yet effective way to practice using loops and handling output formatting in Python.

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare