Pattern in Python


Pattern Programs in python

Pattern 1


Source Code

rows=5
for i in range(1,rows+1):
	for j in range(1,i+1):
			print(j ,end= " ")
	print("")

Output

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Pattern 2


Source Code

rows=70
for i in range(65,rows):
	for j in range(65,i+1):
			print(chr(j) ,end= " ")
	print("")

Output

A
A B
A B C
A B C D
A B C D E
		  

Pattern 3


Source Code

for i in range(5):
	for j in range(i+1):
			print("*" ,end= " ")
	print("")

Output

*
* *
* * *
* * * *
* * * * *

Pattern 4


Source Code

rows=5
    for i in range(1,rows+1):
    	for j in range(1,i+1):
    			print(i ,end= " ")
    	print("")

Output

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Pattern 5


Source Code

 
rows=70
for i in range(65,rows):
	for j in range(65,i+1):
		\print(chr(i) ,end= " ")
	print("")
 

Output

A
B B
C C C
D D D D
E E E E E

Pattern 6


Source Code

n=5
k = 8
for i in range(0, n):
    for j in range(0, k):
        print(end=" ")
    k = k - 2
    for j in range(0, i+1):
        print("* ", end="")
    print()

Output

       
        *
      * *
    * * *
  * * * *
* * * * *

Pattern 7


Source Code

n=5
k = 2 * n - 2
for i in range(0, n):
	for j in range(0, k):
		print(end=" ")
	k = k - 1
	x = 1	
	for j in range(0, i + 1):
		print(x, end=" ")
		x += 1
	print("\r")
k = n - 2

Output

        1
       1 2
      1 2 3
     1 2 3 4
    1 2 3 4 5

Pattern 8


Source Code

r=5
for i in range(r,0,-1):
	for j in range(1,i):
		print(end=" ")
	for k in range(i,r+1):
		print(k,end=" ")
	print(" ")

Output

    5
   4 5
  3 4 5
 2 3 4 5
1 2 3 4 5

Pattern 9


Source Code

n=5
k = 2 * n - 2
for i in range(0, n):
	for j in range(0, k):
		print(end=" ")
	k = k - 1
	x = 65
	for j in range(0, i + 1):
		ch = chr(x)
		print(ch, end=" ")
		x += 1
	print("\r")
k = n - 2

Output

    
     A
    A B
   A B C
  A B C D
 A B C D E
 

Pattern 10


Source Code

alp=65
r=5
for i in range(r,0,-1):
	for j in range(1,i):
		print(end=" ")
	for k in range(i,6):
		print(chr(alp+k-1),end=" ")
	print(" ")

Output

    E
   D E
  C D E
 B C D E
A B C D E

Pattern 11


Source Code

n=5
k = 2 * n - 2
x = 0
for i in range(0, n):
	x += 1
	for j in range(0, k):
		print(end=" ")
	k = k - 1
	for j in range(0, i + 1):
		print("*", end=" ")
	print(" ")
k = n - 2

Output

	*
       * *
      * * *
     * * * *
    * * * * *
	

Pattern 12


Source Code

n=5
k = 2 * n - 2
x = 0
for i in range(0, n):
	x += 1
	for j in range(0, k):
		print(end=" ")
	k = k - 1
	for j in range(0, i + 1):
		print(x, end=" ")
	print(" ")
k = n - 2

Output

        1
       2 2
      3 3 3
     4 4 4 4
    5 5 5 5 5

Pattern 13


Source Code

n=5
k = 2 * n - 2
x = 65
for i in range(0, n):
	ch = chr(x)
	x += 1
	for j in range(0, k):
		print(end=" ")
	k = k - 1
	for j in range(0, i + 1):
		print(ch, end=" ")
	print("\r")

Output

       A
      B B
     C C C
    D D D D
   E E E E E
   

Pattern 14


Source Code

rows=5
for i in range(rows, 0, -1):
    for j in range(1, i+1):
        print(j, end=" ")    
    print("")

Output

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern 15


Source Code

rows = 6
for i in range(0, rows):
    for j in range(rows-1, i, -1):
        print(j,  end=" ")    
    print('')

Output

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

Pattern 16


Source Code

rows = 5;
for i in range(rows, 0,-1):
    for j in range(rows, i-1,-1):
        print(j, end=" ")
    print()
 

Output

5
5 4
5 4 3
5 4 3 2
5 4 3 2 1

Pattern 17


Source Code

cn = 1  
s = 2  
rows = 5  
 
for i in range(rows):  
    for j in range(1, s):  
        print(cn, end=' ')  
        cn += 1  
    print("")  
    s += 1  

Output

1
2  3
4  5  6
7  8  9  10
11 12 13 14 15

Pattern 18


Source Code

rows=70
for i in range(rows, 65, -1):
    for j in range(65, i):
        print(chr(j), end=" ")    
    print("")

Output

A B C D E
A B C D
A B C
A B
A

Pattern 19


Source Code

rows = 70
for i in range(64, rows):
    for j in range(rows-1, i, -1):
        print(chr(j),  end=" ")    
    print('')

Output

E D C B A
E D C B
E D C
E D
E
 

Pattern 20


Source Code

rows = 69;
for i in range(rows, 64,-1):
    for j in range(rows, i-1,-1):
        print(chr(j), end=" ")
    print()
 

Output

E
E D
E D C
E D C B
E D C B A

Pattern 21


Source Code

n=7
alpha=65
for i in range(1,n):
	for j in range(1,i):
		print(chr(alpha),end=" ")
		alpha+=1
	print()

Output

A
B C
D E F
G H I J
K L M N O

Pattern 22


Source Code

rows = 5
c = 1
 
for i in range(1, rows+1):
    for space in range(1, rows-i+1):
        print(" ",end="")
    for j in range(0, i):
        if j==0 or i==0:
            c = 1
        else:
            c = c * (i - j)//j
        print(c, end = " ")
    print()

Output

    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1

Pattern 23


Source Code

alp=65
r=5
for i in range(1,r+1):
	for j in range(r,i,-1):
		print(end=" ")
	t=int(1)
	for k in range(1,i+1):
		print(chr(alp-1+t),end=" ")
		t=int(t*(i-k)/(k))
	print(" ")
 

Output

    A
   A A
  A B A
 A C C A
A D F D A

Pattern 24


Source Code

 rows=5
for i in range(1,rows+1):
	for j in range(1,i+1):
			print(j ,end= " ")
	print("")
for i in range(rows, 0, -1):
    for j in range(1, i):
        print(j, end=" ")    
    print("")
 

Output

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern 25


Source Code

rows=69
for i in range(65,rows+1):
	for j in range(65,i+1):
			print(chr(j) ,end= " ")
	print("")
for i in range(rows, 65, -1):
    for j in range(65, i):
        print(chr(j), end=" ")    
    print("")
 

Output

A
A B
A B C
A B C D
A B C D E
A B C D
A B C
A B
A

Pattern 26


Source Code

rows=5
for i in range(1,rows+1):
	for j in range(1,i+1):
			print("*" ,end= " ")
	print("")
for i in range(rows, 0, -1):
    for j in range(1, i):
        print("*", end=" ")    
    print("")

Output

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Pattern 27


Source Code

n=5
k = 2 * n - 2
for i in range(0, n-1):
	for j in range(0, k):
		print(end=" ")
	k = k - 2
	for j in range(0, i + 1):
		print("* ", end="")
	print(" ")
k = -1
for i in range(n-1,-1,-1):
	for j in range(k,-1,-1):
		print(end=" ")
	k = k + 2
	for j in range(0, i + 1):
		print("* ", end="")
	print(" ")
 

Output

        *
      * *
    * * *
  * * * *
* * * * *
  * * * *
    * * *
      * *
        *

Pattern 28


Source Code

rows=5
for i in range(rows, 0, -1):
    for j in range(1, i+1):
        print(j, end=" ")    
    print("")
for i in range(2,rows+1):
	for j in range(1,i+1):
			print(j ,end= " ")
	print("")

Output

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Pattern 29


Source Code

rows = 5
for i in range(0, rows + 1):
    for j in range(rows - i, 0, -1):
        print(j,end=" ")
    print("")
rows = 6
for i in range(2, rows):
    for j in range(i, 0, -1):
        print(j,end=" ")
    print("")

Output

5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1

Pattern 30


Source Code

rows=70
for i in range(rows, 65, -1):
    for j in range(65, i):
        print(chr(j), end=" ")    
    print("")
for i in range(66,rows):
	for j in range(65,i+1):
			print(chr(j) ,end= " ")
	print("")

Output

A B C D E
A B C D
A B C
A B
A
A B
A B C
A B C D
A B C D E

Pattern 31


Source Code

alp=65
r=5
for i in range(r,0,-1):
	for j in range(i,0,-1):
		print(chr(alp+j-1),end=" ")
	print(" ")
for i in range(2,r+1):
	for j in range(i,0,-1):
		print(chr(alp+j-1),end=" ")
	print(" ")

Output

E D C B A
D C B A
C B A
B A
A
B A
C B A
D C B A
E D C B A

Pattern 32


Source Code

rows=5
for i in range(rows, 0, -1):
    for j in range(1, i+1):
        print("*", end=" ")    
    print("")
for i in range(2,rows+1):
	for j in range(1,i+1):
			print("*" ,end= " ")
	print("")

Output

* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *

Pattern 33


Source Code

rows = 4
 
for i in range(rows):
    for j in range(rows - 1, i - 1, -1):
        print(end = "  ")
    for k in range(i + 1):
        print(k+1, end = " ")
    for l in range(i - 1, -1, -1):
        print(l+1, end = " ")
    print()

Output

        1
      1 2 1
    1 2 3 2 1
  1 2 3 4 3 2 1

Pattern 34


Source Code

rows = 4
alp = 65
 
for i in range(rows):
    for j in range(rows - 1, i - 1, -1):
        print(end = "  ")
    for k in range(i + 1):
        print(chr(alp + k), end = " ")
    for l in range(i - 1, -1, -1):
        print(chr(alp + l), end = " ")
    print()

Output

        A
      A B A
    A B C B A
  A B C D C B A

Pattern 35


Source Code

r=5
for i in range(1,r+1):
	for j in range(1,i):
		print(0,end=" ")
	print(i,end=" ")
	for k in range(i,r):
		print(0,end=" ")
	print(" ")
 

Output

1 0 0 0 0
0 2 0 0 0
0 0 3 0 0
0 0 0 4 0
0 0 0 0 5

Pattern 36


Source Code

r=5
for i in range(1,r+1):
	for j in range(r,i,-1):
		print(1,end=" ")
	for k in range(0,i):
		print(i,end=" ")
	print(" ")

Output

1 1 1 1 1
1 1 1 2 2
1 1 3 3 3
1 4 4 4 4
5 5 5 5 5

Pattern 37


Source Code

r=5
alp=65
for i in range(1,r+1):
	for j in range(r,i,-1):
		print(chr(alp),end=" ")
	for k in range(0,i):
		print(chr(alp+i-1),end=" ")
	print(" ")

Output

A A A A A
A A A B B
A A C C C
A D D D D
E E E E E

Pattern 38


Source Code

r=6
for i in range(1,r):
	for j in range(r,i,-1):
		print(end=" ")
	for k in range(1,i+1):
		print(k,end=" ")
	print(" ")
for i in range(1,r):
	for j in range(0,i+1):
		print(end=" ")
	for k in range(1,r-i):
		print(k,end=" ")
	print(" ")
 

Output

     1
    1 2
   1 2 3
  1 2 3 4
 1 2 3 4 5
  1 2 3 4
   1 2 3
    1 2
     1

Pattern 39


Source Code

r=6
alp=63
for i in range(1,r):
	for j in range(r,i,-1):
		print(end=" ")
	for k in range(1,i+1):
		print(chr(alp+k+1),end=" ")
	print(" ")
for i in range(1,r):
	for j in range(0,i+1):
		print(end=" ")
	for k in range(1,r-i):
		print(chr(alp+k+1),end=" ")
	print(" ")
 

Output

     A
    A B
   A B C
  A B C D
 A B C D E
  A B C D
   A B C
    A B
     A
 

Pattern 40


Source Code

n = 5
for i in range(n):
    for j in range(n - i - 1):
        print(" ", end="")
    for k in range(2 * i + 1):
        print("*", end="")
    print()
for i in range(1,n):
    for j in range(i):
        print(" ", end="")
    for j in range(2*(n-i)-1):
        print("*", end="")
    print()
 

Output

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

List of Programs


Sample Programs


Python Database Connection


Python Flask


Python Tkinder Tutorial