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