Python | Print an Inverted Star Pattern program

Python | Print an Inverte Star Pattern programs: Here we are going to print inverted star pattern of desired sizes, . Python Program to Print an Inverted Star Pattern. Take a value from the user and store it in a variable n.
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.Multiply empty spaces with n-i and ‘*’ with i and print both of them.Exit. Image result for Print an Inverted Star Pattern program
printf(“Enter the number of rows = “); scanf(“%u”,&rows); printf(“Enter the number of rows = “); scanf(“%u”,&rows);

The pattern contains N rows and each row contains N-x + 1 columns (where x is the current row number). So to print the star inner loop iterate x to row (N is row here).

Steps to Print Pattern in Python

Accept the number of rows from a user using the input() function to decide the size of a pattern. Next, write an outer loop to Iterate the number of rows using a for loop and range() function. Next, write the inner loop or nested loop to handle the number of columns.

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).

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

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

Print Pyramid Pattern of Stars () Let’s start with pyramid pattern of stars (). In this section, there are more than 6 programs. All programs prints pyramid pattern of stars, but in different-different ways. Let’s have a look at these programs one by one.

Half Pyramid of Stars () This program prints half-pyramid of stars () of 5 lines. That is, one star in first row, two stars in second row, three stars in third row, and so on, upto five stars in fifth row. All stars starting from first column, or from left side:

# 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 * '*')

Explanation:

  • The 1st number of row is store in variable n.
  • Then the for loop enables i to range between n-i to 0 with a decrement of 1 with each iteration.

Output Print an Inverted Star Pattern program

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

Leave a Reply