All star patterns using Python programming Language | Python Code Examples

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

Star pattern : 1

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

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

Star pattern : 2

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

Star pattern : 3

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

Star pattern : 4

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

Star pattern 5

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

Star pattern 6

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

Star pattern 7

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

Star pattern 8

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

Star pattern 9

for e in range (5,0,-1):
    print((5-e) * ' ' + e * '*')

Star pattern 10

for g in range (6,0,-1):
    print(g * ' ' + (6-g) * '*')

Star pattern 11

for row in range(1,5):
    for col in range(1,8):
        if (row==4 or row+col==5 or col-row==3):
            print("*",end="")
        else:
            print(" ",end="")
    print()

Star pattern 12

n=5;
for r in range(0,n):
    for c in range(0,n):
        if r==0 or c==(n-1) or r==c:
            print("*",end="")
        else:
            print(end=" ")
    print()

Star pattern 13 : ‘A’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (((column == 1 or column == 5) and row != 0) or ((row == 0 or row == 3) and (column > 1 and column < 5))):
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 14 : ‘D’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 5)) or (column == 5 and row != 0 and row != 6)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 15 : ‘E’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 6)) or (row == 3 and column > 1 and column < 5)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 16 : ‘G’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if ((column == 1 and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5) or (row == 3 and column > 2 and column < 6) or (column == 5 and row != 0 and row != 2 and row != 6)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 17 : ‘L’ Pattern in Python

*
*
*
*
*
*
*****
result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (column == 1 or (row == 6 and column != 0 and column < 6)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 18 : ‘M’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (column == 1 or column == 5 or (row == 2 and (column == 2 or column == 4)) or (row == 3 and column == 3)):  
            result_str=result_str+"* "    
        else:      
            result_str=result_str+"  "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 19 : ‘O’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (((column == 1 or column == 5) and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 20 : ‘P’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (column == 1 or ((row == 0 or row == 3) and column > 0 and column < 5) or ((column == 5 or column == 1) and (row == 1 or row == 2))):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 21 : ‘X’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (((column == 1 or column == 5) and (row > 4 or row < 2)) or row == column and column > 0 and column < 6 or (column == 2 and row == 4) or (column == 4 and row == 2)):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

Star pattern 22 : ‘Z’ Pattern in Python

result_str="";    
for row in range(0,7):    
    for column in range(0,7):     
        if (((row == 0 or row == 6) and column >= 0 and column <= 6) or row+column==6):  
            result_str=result_str+"*"    
        else:      
            result_str=result_str+" "    
    result_str=result_str+"\n"    
print(result_str);

 

Leave a Comment