Python Program to Print an Inverted Star Pattern

This is a Python Program to read a number n and print an inverted star pattern of the desired size.

Problem Description

The program takes a number n and prints an inverted star pattern of the desired size.

Problem Solution

1. Take a value from the user and store it in a variable n.
2. Use a for loop where the value of i ranges between the values of n-1 and 0 with a decrement of 1 with each iteration.
3. Multiply empty spaces with n-i and ‘*’ with i and print both of them.
4. Exit.

Program/Source Code

Here is the source code of the Python Program to read a number n and print an inverted star pattern of the desired size. The program output is also shown below.

n=int(input("Enter number of rows: "))
for i in range (n,0,-1):
    print((n-i) * ' ' + i * '*')
Program Explanation

1. User must first enter the value and store it in a variable n.
2. The for loop enables i to range between n-1 and 0 with a decrement of 1 with each iteration.
3. For each iteration, ” ” is multiplied with n-i and ‘*’ is multiplied with i to ensure correct spacing of the stars.
4. The required pattern is printed.

advertisement
Runtime Test Cases
 
Case 1:
Enter number of rows: 5
*****
 ****
  ***
   **
    *
 
Case 2:
Enter number of rows: 10
**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *

Sanfoundry Global Education & Learning Series – 1000 Python Programs.

If you wish to look at all Python Programming examples, go to 1000 Python Programs.

🎓 Register Today for Free C++ Certification - January 2026

👉 For weekly programming practice and certification updates, join Sanfoundry’s official WhatsApp & Telegram channels

advertisement
Manish Bhojasia – Founder & CTO at Sanfoundry

I’m Manish, Founder & CTO at Sanfoundry, with 25+ years of experience across Linux systems, SAN technologies, advanced C programming, and building large-scale, performance-driven learning and certification platforms focused on clear skill validation.

LinkedIn  ·  YouTube MasterClass  ·  Telegram Classes  ·  Career Guidance & Conversations