Python Program to Print an Inverted Star Pattern

PythonServer Side ProgrammingProgramming

When it is required to print an inverted star pattern in Python, the 'for' loop can be used. This helps iterate over a range of numbers, and print the required character in the required frequency, and the count can be decremented after every iteration.

Below is a demonstration for the same −

Example

Live Demo

N=6
print("The value of 'N' has been initialized to "+str(N))
print("The inverted stars are being displayed")
for i in range (N, 0, -1):
   print((N-i) * ' ' + i * '*')

Output

The value of 'N' has been initialized to 6
The inverted stars are being displayed
******
 *****
  ****
   ***
    **
     *

Explanation

  • The value of 'N' is initialized and displayed on the console.
  • The 'for' loop is iterated over 'N' numbers.
  • The required character is printed on the screen.
  • Its value is decremented in the next step.
  • This is displayed on the console.
raja
Published on 13-Mar-2021 05:55:26
Advertisements