Reverse Star Pattern in Python

Reverse star pattern in Python | In the below programs, we will print reverse star patterns using for loop and while loop.

Reverse Star Pattern Programs in Python

Reverse Star Pattern Program 1

Enter the number of rows: 5
* * * *
* * *
* *
*

Enter the number of rows: 7
* * * * * *
* * * * *
* * * *
* * *
* *
*

# Python star pattern to print reverse left half pyramid

def pattern(n):
   for i in range(n):
      for j in range(n-i-1):
         # print star
         print("* ",end="")
      print(" ")
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print reverse left half pyramid 

def pattern(n):
   i = 1
   while i <= n :
      j = n
      while j >= i:
         # print star
         print("*", end=" ")
         j = j - 1
      print()
      i = i + 1
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 2

Enter the number of rows: 6

  * * * * *
    * * * * 
      * * * 
        * * 
          * 
# Python star pattern to print reverse right half pyramid

def pattern(n):
   for i in range(n-1):
      for j in range(i+1):
         # print space
         print(" ",end=" ")

      for k in range(n-i-1):
         # print star
         print("* ",end="")
      print()
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print reverse right half pyramid 

def pattern(n):
   i = n
   while i>=1:
      # print star
      print(" "*(n-i) + "*" * i)
      i-=1 
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 3

Enter the number of rows: 5

* * * * * * * * * 
  * * * * * * * 
    * * * * * 
      * * * 
        * 
# Python star pattern to print reverse triangle

def pattern(n):
   for i in range(n, 0, -1):
      for j in range(n-i):
         # print space
         print(" ",end=" ")
      
      for j in range(2*i-1):
         # print star
         print("* ",end="")
      print()
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print reverse triangle

def pattern(n):
   i = n
   while i>=1:
      # print star
      print(" "*(n-i) + "* " * i)
      i-=1 
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 4

Enter the number of rows: 3
*
* *
* * *
* *
*

# Python star pattern to print right pascal triangle

def pattern(n):
   # upper pyramid
   for i in range(n):
      for j in range(i+1):
         # print star
         print("* ",end="")
      print("\r")
      
   # lower pyramid
   for i in range(n):
      for j in range(n-i-1):
         # print star
         print("* ",end="")
      print("\r")
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print right pascal triangle

def pattern(n):
   # upper pyramid
   i = 1
   while i<n:
      # print star
      print("* " * i)
      i+=1

   # lower pyramid
   i = n
   while i>=1:
      # print star
      print("* " * i)
      i-=1
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 5

Enter the number of rows: 4

      * 
    * * 
  * * * 
* * * * 
  * * * 
    * * 
      * 
# Python star pattern to print left pascal triangle

def pattern(n):
   # upper pyramid
   for i in range(n):
      for j in range(n-i-1):
         # print space
         print(" ", end=" ")

      for j in range(i+1):
         # print star
         print("* ",end="")
      print()

   # lower pyramid
   for i in range(n-1):
      for j in range(i+1):
         # print space
         print(" ",end=" ")

      for j in range(n-i-1):
         # print star
         print("* ",end="")
      print()
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print left pascal triangle

def pattern(n):
   # upper pyramid
   i = 1
   while i<n:
      # print star
      print(" "*(n-i) + "*" * i)
      i+=1

   # lower pyramid
   i = n
   while i>=1:
      # print star
      print(" "*(n-i) + "*" * i)
      i-=1
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 6

Enter the number of rows: 6

          * 
        * * * 
      * * * * * 
    * * * * * * * 
  * * * * * * * * * 
* * * * * * * * * * * 
  * * * * * * * * * 
    * * * * * * * 
      * * * * * 
        * * * 
          * 
# Python star pattern to print diamond

def pattern(n):
   # upper pyramid
   for i in range(n):
      for j in range(n-i-1):
         print(" ", end=" ")
      for j in range(2*i+1):
         # print star
         print("*", end=" ")
      print()

   # lower pyramid
   for i in range(n-1):
      for j in range(i+1):
         print(" ", end=" ")
      for j in range(2*(n-i-1)-1):
         # printing stars
         print("*", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print diamond

def pattern(n):
   # upper pyramid
   i = 1
   while i<n:
      # print star
      print(" "*(n-i) + "* " * i)
      i+=1 

   # lower pyramid
   i = n
   while i>=1:
      # print star
      print(" "*(n-i) + "* " * i)
      i-=1
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 7

Enter the number of rows: 5

* * * * * * * * * 
  * * * * * * * 
    * * * * * 
      * * * 
        * 
      * * * 
    * * * * * 
  * * * * * * * 
* * * * * * * * *
# Python star pattern to print hourglass

def pattern(n):
   # reverse pyramid
   for i in range(n-1):
      for j in range(i):
         # print space
         print(" ", end=" ")
      for j in range(2*(n-i)-1):
         # print star
         print("*", end=" ")
      print()

   # upper pyramid
   for i in range(n):
      for j in range(n-i-1):
         # print space
         print(" ", end=" ")
      for j in range(2*i+1):
         # print star
         print("*", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Using While Loop

# Python star pattern to print hourglass

def pattern(n):
   # reverse pyramid
   i = n
   while i>1:
      # print star
      print(" "*(n-i) + "* " * i)
      i-=1

   # upper pyramid
   i = 1
   while i<=n:
      # print star
      print(" "*(n-i) + "* " * i)
      i+=1
 
# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Hollow Reverse Star Pattern in Python

In the below programs, we will print the hollow reverse star pattern using the For Loop and While Loop.

Reverse Star Pattern Program 8

Enter the number of rows: 6

* * * * * *
*       *
*     * 
*   * 
* * 
* 
# Python star pattern to print hollow reverse left half pyramid

def pattern(n):
   for i in range(n, 0, -1):
      for j in range(i, 0, -1):
         if i == 1 or i == n or j == 1 or j == i:
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 9

Enter the number of rows: 5

  * * * * * * * * * 
    *           * 
      *       * 
        *   * 
          * 
# Python star pattern to print hollow reverse left half pyramid

def pattern(n):
   for i in range(1, n+1):
      for j in range(0, i):
         # print space
         print(" ", end=" ")

      for j in range(1, (n*2 - (2*i-1)) + 1):
         if i == 1 or j == 1 or j ==(n*2 -(2*i-1)):
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 10

Enter the number of rows: 4

        * 
      *   * 
    *       * 
  *           * 
    *       * 
      *   * 
        * 
# Python star pattern to print hollow diamond

def pattern(n):
   # upper hollow pyramid
   for i in range(n):
      for j in range(n-i-1):
         # print space
         print(" ", end=" ")
      for j in range(2*i+1):
         if j == 0 or j == 2*i:
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()

   # lower hollow pyramid
   for i in range(n-1):
      for j in range(i+1):
         # print space
         print(" ", end=" ")
      for j in range(2*(n-i-1)-1):
         if j == 0 or j == 2*(n-i-1)-2:
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Reverse Star Pattern Program 11

Enter the number of rows: 5

* * * * * * * * * 
  *           * 
    *       * 
      *   * 
        * 
      *   * 
    *       * 
  *           * 
* * * * * * * * * 
# Python star pattern to print hollow hourglass

def pattern(n):
   # upper hollow pyramid
   for i in range(n, 0, -1):
      for j in range(n-i):
         # print space
         print(" ", end=" ")
      for j in range(1, 2*i):
         if i==1 or i==n or j==1 or j==2*i-1:
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()
   
   # lower hollow pyramid
   for i in range(2, n+1):
      for j in range(n-i):
         # print space
         print(" ", end=" ")
      for j in range(1, 2*i):
         if i==n or j==1 or j==2*i-1:
            # print star
            print("*", end=" ")
         else:
            # print space
            print(" ", end=" ")
      print()

# take input
n = int(input('Enter the number of rows: '))

# calling function
pattern(n)

Also See:- Pattern Programs in C

Leave a Comment

Your email address will not be published.