Header Ads

Python Program to Print an Inverted Star Pattern

Python Program to Print an Inverted Star Pattern
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 * '*')


Runtime Test Cases

Case 1:
Enter number of rows: 5
*****
 ****
  ***
   **
    *
Case 2:
Enter number of rows: 10
**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *







Powered by Blogger.