Open In App

Python | Print an Inverted Star Pattern

Last Updated : 24 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

An inverted star pattern involves printing a series of lines, each consisting of stars (*) that are arranged in a decreasing order. Here we are going to print inverted star patterns of desired sizes in Python

Examples:

1) Below is the inverted star pattern of size n=5 
(Because there are 5 horizontal lines
or rows consist of stars).

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

2) Below is the inverted star pattern of size n=10
(Because there are 5 horizontal lines
or rows consist of stars).

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

The provided Python 3 code generates an inverted star pattern with variable n representing the number of rows. The code iterates through a loop, decrementing i from n to 1. For each iteration, the print function is used to generate the pattern. It multiplies (n-i) with space (‘ ‘) and i with asterisk (‘*’) to create the appropriate number of spaces before the stars. This leads to an inverted triangle pattern where the number of stars in each row decreases while the spaces before them increase, creating the desired inverted star pattern.

Let’s see Python program to print inverted star pattern: 

Python3




# python 3 code to print inverted star
# pattern
 
# n is the number of rows in which
# star is going to be printed.
n=11
 
# i is going to be enabled to
# range between n-i t 0 with a
# decrement of 1 with each iteration.
# and in print function, for each iteration,
# ” ” is multiplied with n-i and ‘*’ is
# multiplied with i to create correct
# space before of the stars.
for i in range (n, 0, -1):
    print((n-i) * ' ' + i * '*')


Output

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

Time complexity: O(n) for given input n
Auxiliary Space: O(1)

Example2: Using Recursion

Here we will implement the inverted star pattern using Recursion.

Python3




def inverted_star_pattern_recursive(height):
    if height > 0:
        print("*" * height)
        inverted_star_pattern_recursive(height - 1)
 
height = 5
inverted_star_pattern_recursive(height)


Output:

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



Previous Article
Next Article

Similar Reads

Program to Print Inverted Left Half Pyramid Pattern (Star Pattern)
Given an integer N, the task is is to print a left half pyramid pattern with N rows. In this pattern, the first row contains N stars, the second row contains N - 1 stars, and so forth until the Nth row, which contains only 1 star. All the stars are aligned to the right. Examples: Input: 3Output: *** ** * Input: 5Output: ***** **** *** ** * Approach
4 min read
Program to Print Inverted Right Half Pyramid Pattern (Star Pattern)
Given an integer N, print N rows of inverted right half pyramid pattern. In inverted right half pattern of N rows, the first row has N number of stars, second row has (N - 1) number of stars and so on till the Nth row which has only 1 star. Examples: Input: n = 5Output:*************** Input: n = 3Output:****** Approach: The problem can be solved us
3 min read
Program to Print Inverted Full Pyramid Pattern (Star Pattern)
Given an integer N, the task is to print a pattern of N rows representing an inverted full pyramid. In this pattern, the first row has (2 * N - 1) stars, the second row has (2 * N - 3) stars, and so on until the Nth row, which has only 1 star. All stars are center-aligned. Examples: Input: 3Output: ***** *** * Input: 5Output: ********* ******* ****
4 min read
Program to Print Right Half Pyramid Pattern (Star Pattern)
Given an integer N, print N rows of right half pyramid pattern. In right half pattern of N rows, the first row has 1 star, second row has 2 stars and so on till the Nth row which has N stars. All the stars are left aligned. Examples: Input: 3Output: ****** Input: 5Output: *************** Approach: The problem can be solved using two nested loops. T
3 min read
Program to Print Left Half Pyramid Pattern (Star Pattern)
Given an integer N, the task is to print N rows of left half pyramid pattern. In left half pattern of N rows, the first row has 1 star, second row has 2 stars and so on till the Nth row which has N stars. All the stars are right aligned. Examples: Input: 3Output: * ***** Input: 5Output: * ** *** ********* Approach: The problem can be solved using t
4 min read
Program to Print Butterfly Pattern (Star Pattern)
Given an integer N, print N rows of Butterfly pattern. Examples: Input: 3Output: * *** ********* *** * Input: 5Output: * *** ***** ******* ***************** ******* ***** *** * Approach: The problem can be solved using three nested loops inside an outer loop. The outer loop will run for the rows, the first inner loop will print the stars, the secon
6 min read
Program to Print Full Pyramid Pattern (Star Pattern)
Given an integer N, the task is to print a full pyramid pattern with N rows. In this pattern, each row contains an odd number of stars, ranging from 1 star in the first row to (2 * N - 1) stars in the Nth row. All the stars are center-aligned. Examples: Input: 3Output: * ******** Input: 5Output: * *** ***** **************** Approach: The problem ca
4 min read
Python program to print the Inverted heart pattern
Let us see how to print an inverted heart pattern in Python. Example: Input: 11 Output: * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* ********* ******** ******* ****** ***** **** Input: 15 Output: * *** ***** ******* ********* *********** ************* ***********
2 min read
Program to print V and inverted-V pattern
Inverted V pattern: Given the value of n, print the inverted V pattern.Examples : Input : n = 5 Output : E D D C C B B A A Input : n = 7 Output : G F F E E D D C C B B A A Below is the program to print the above pattern C/C++ Code // C++ Implementation to print the pattern #include <bits/stdc++.h> using namespace std; // Function definition v
8 min read
Python Program to Print Christmas Tree Star Pattern
The "Python program to print Tree pattern" is a piece of code that creates a tree pattern out of asterisks (*) using Python. The indentation and amount of asterisks per row are controlled via loops and string manipulation to produce the tree pattern, which is presented on the console. Print Christmas Tree Star Pattern using LoopsThis program uses n
5 min read