Skip to content

Table of Contents

SNo.Link
1Solid Square
2Right-Angled Triangle
3Inverted Right-Angled Triangle
4Right-Aligned Triangle
5Inverted Right-Aligned Triangle
6Full Pyramid
7Inverted Pyramid
8Diamond
9Flyod's Triangle
10Pascal's Triangle
11Binary Triangle
12Palindrome Number
13Hollow Square
14Hollow Pyramid
15Butterfly
16Cross
17Hourglass
18Hollow Diamond

1. Solid Square

Python
#Expected Output for n = 5
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
R\Cj=1j=2j=3j=4j=5
i=1*****
i=2*****
i=3*****
i=4*****
i=5*****
  • Both i and j loop should run for n times
Python
n = int(input())
for i in range(n):
    for j in range(n):
        print("*", end=" ")
    print()
Python
#String Multiplication
n = int(input())
for i in range(n):
    print("* " * n)

2. Right-Angled Triangle

Python
#Expected Output for n = 5
*
* *
* * *
* * * *
* * * * *
Python
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Python
A
A B
A B C
A B C D
A B C D E
R\Cj=1j=2j=3j=4j=5
i=1*
i=2**
i=3***
i=4****
i=5*****

* should be printed until j<=i

Python
n=int(input())
for i in range(1, n+1):
    for j in range(i):
        print("*", end=" ")
    print()
Python
#String multiplication
n=int(input())
for i in range(1, n+1):
    print("* " * i)
Python
n=int(input())
for i in range(1, n+1):
    for j in range(1, i+1):
        print(j, end=" ")
    print()
Python
n=int(input())
for i in range(1, n+1):
    for j in range(i):
        print(chr(65+j), end=" ")
    print()

3. Inverted Right-Angled Triangle

Python
* * * * *
* * * *
* * *
* *
*
Python
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Python
A B C D E
A B C D
A B C
A B
A
R\Cj=1j=2j=3j=4j=5
i=1*****
i=2****
i=3***
i=4**
i=5*
Python
n=int(input())
for i in range(n, 0, -1):
    for j in range(i):
        print("*", end=" ")
    print()
Python
n=int(input())
for i in range(n, 0, -1):
    for j in range(1, i+1):
        print(j, end=" ")
    print()
Python
n=int(input())
for i in range(n, 0, -1):
    for j in range(i):
        print(chr(65+j), end=" ")
    print()

4. Right-Aligned Triangle

Python
#Expected Output for n = 5
    *
   **
  ***
 ****
*****
R\Cj=1j=2j=3j=4j=5
i=1*
i=2**
i=3***
i=4****
i=5*****
  • no. of white spaces: n-i and no. of '*' : i
Python
n=int(input())
for i in range(1,n+1):
    for j in range(n-i): #Loop runs for n-i times, since we have n-i white spaces
        print(' ',end='')
    for k in range(i): #Loop runs for i times, since we have i '*'
        print('*',end='')
    print()
Python
n=int(input())
for i in range(1,n+1):
    print(' '*(n-i)+'*'*i) #String concatenation

5. Inverted Right-Aligned Triangle

Python
*****
 ****
  ***
   **
    *
R\Cj=1j=2j=3j=4j=5
i=1*****
i=2****
i=3***
i=4**
i=5*
Python
n = int(input())
for i in range(n, 0, -1):
    print(" " * (n - i) + "*" * i)

6. Full Pyramid

Python
    *
   ***
  *****
 *******
*********
Python
    * 
   * * 
  * * * 
 * * * * 
* * * * *
i=1*
i=2***
i=3*****
i=4*******
i=5*********
  • 2*i-1 '*' and n-i spaces
i=1*W
i=2*W*W
i=3*W*W*W
i=4*W*W*W*W
i=5*W*W*W*W*

Here W is the white space

Python
n = int(input())
for i in range(1, n + 1):
    print(" " * (n - i) + "*" * (2 * i - 1))
Python
n = int(input())
for i in range(1,n+1):
    print(' '*(n-i)+'* '*i)

7. Inverted Pyramid

Python
* * * * * 
 * * * * 
  * * * 
   * * 
    *
Python
*********
 *******
  *****
   ***
    *
Python
n = int(input())
for i in range(n,0,-1):
    print(' '*(n-i)+'* '*i)
Python
n = int(input())
for i in range(n,0,-1):
    print(" " * (n - i) + "*" * (2 * i - 1))

8. Diamond

Python
    * 
   * * 
  * * * 
 * * * * 
* * * * * 
 * * * * 
  * * * 
   * * 
    *
Python
n = int(input())
for i in range(1,n+1):
    print(' '*(n-i)+'* '*i)
for i in range(n-1,0,-1):
    print(' '*(n-i)+'* '*i)

9. Flyod's Triangle

Python
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15
R\Cj=1j=2j=3j=4j=5
i=11
i=223
i=3456
i=478910
i=51112131415
Python
n = int(input())
num = 1
for i in range(n+1):
    for j in range(i):
        print(num, end=' ')
        num += 1
    print()

10. Pascal's Triangle

Python
      1 
     1 1 
    1 2 1 
   1 3 3 1 
  1 4 6 4 1 
 1 5 10 10 5 1
R\Cj=1j=2j=3j=4j=5j=6
i=11
i=211
i=3121
i=41331
i=514641
i=615101051
  • Pascal's Triangle formula: val = val * (i - j) // (j + 1)
  • n-i spaces and i no. of numbers
Python
n = int(input())
for i in range(n):
    print(' '*(n-i),end='')
    val = 1
    for j in range(i+1):
        print(val, end=' ')
        val = val * (i - j) // (j + 1)
    print()

11. Binary Triangle

Python
1 
0 1 
1 0 1 
0 1 0 1 
1 0 1 0 1
R\Cj=1j=2j=3j=4j=5
i=11
i=201
i=3101
i=40101
i=510101
  • print 1 if i + j = even else 0
Python
n = int(input())
for i in range(1,n+1):
    for j in range(1,i+1):
        if (i+j) % 2 == 0:
            print(1, end=' ')
        else:
            print(0, end=' ')
    print()

12. Palindrome Number

Python
    1
   121
  12321
 1234321
123454321
i=11
i=2121
i=312321
i=41234321
i=5123454321
  • n-i spaces
  • Split the pattern i.e. jth loop to print ascending order and kth loop to print descending order but starting from i-1
Python
n = int(input())
for i in range(1,n+1):
    print(' '*(n-i),end='')
    for j in range(1,i+1):
        print(j, end='')
    for k in range(i-1,0,-1):
        print(k, end='')
    print()

13. Hollow Square

Python
* * * * *  
*       *  
*       *  
*       *   
* * * * *
R\Cj=1j=2j=3j=4j=5
i=1*****
i=2**
i=3**
i=4**
i=5*****
  • '*' is being printed at i = 1 , n and j = 1 , n else whitespace
Python
n = int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        if i == 1 or i == n or j == 1 or j == n:
            print('*', end=' ')
        else:
            print(' ',end=' ')
    print()

14. Hollow Pyramid

Python
    *    
   * *   
  *   *  
 *     * 
*********
i=1*
i=2**
i=3**
i=4**
i=5*********
  • n-i spaces and jth loop for 1 to 2*i times
  • We need to print * at the ends i.e. j = 1 or j = 2 * i -1 and i = n else whitespace
Python
n = int(input())
for i in range(1, n + 1):
    print(" " * (n - i), end="")
    for j in range(1, 2 * i):
        if j == 1 or j == 2 * i - 1 or i == n:
            print("*", end="")
        else:
            print(" ", end="")
    print()

15. Butterfly

Python
*        *
**      **
***    ***
****  ****
**********
****  ****
***    ***
**      **
*        *
i=1**
i=2****
i=3******
i=4********
i=5**********
i=4********
i=3******
i=2****
i=1**
  • Split into upper and lower halves. 2i no. of stars and 2 * (n-i) whitespaces
Python
n = int(input())
for i in range(1, n + 1):
    print("*" * i + " " * (2 * (n - i)) + "*" * i)
for i in range(n-1, 0, -1):
    print("*" * i + " " * (2 * (n - i)) + "*" * i)

16. Cross

Python
*       *
  *   *  
    *    
  *   *  
*       *
R\Cj=1j=2j=3j=4j=5
i=1**
i=2**
i=3*
i=4**
i=5**
  • Print * if i==j or i+j == n-1
Python
n = int(input())
for i in range(n):
    for j in range(n):
        if i == j or i + j == n - 1:
            print("*", end=" ")
        else:
            print(" ", end=" ")
    print()

17. Hourglass

Python
* * * * * 
 * * * * 
  * * * 
   * * 
    * 
   * * 
  * * * 
 * * * * 
* * * * *
i=1*****
i=2****
i=3***
i=4**
i=5*
i=4**
i=3***
i=2****
i=1*****
Python
n = int(input())
for i in range(n,0,-1):
    print(' '*(n-i)+'* '*i)
for i in range(1,n+1):
    print(' '*(n-i)+'* '*i)

18. Hollow Diamond

Python
    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *
i=1*
i=2**
i=3**
i=4**
i=5**
i=4**
i=3**
i=2**
i=1*
  • Similar to Hollow Pyramid except you don't write i = n and ith loop from n-1 for lower-half
Python
n = int(input())
for i in range(1, n + 1):
    print(" " * (n - i), end="")
    for j in range(1, 2 * i):
        if j == 1 or j == 2 * i - 1:
            print("*", end="")
        else:
            print(" ", end="")
    print()
for i in range(n-1, 0,-1):
    print(" " * (n - i), end="")
    for j in range(1, 2 * i):
        if j == 1 or j == 2 * i - 1:
            print("*", end="")
        else:
            print(" ", end="")
    print()

© 2026 pnote. All rights reserved.