- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Print an Inverted Star Pattern
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.
Advertisements