Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Looping Statements

Display a pattern (e.g., pyramid, triangle using *) - Python Program

Example 1 :

# Pyramid pattern rows = int(input("Enter number of rows: ")) for i in range(1, rows + 1): print(" " * (rows - i) + "* " * i)

Output

 
OUTPUT  :
Enter number of rows: 5
    * 
   * * 
  * * * 
 * * * * 
* * * * * 
 

Explanation

  • " " * (rows - i) creates leading spaces for alignment.
  • "* " * i prints increasing stars.
  • Simple left-aligned pyramid.