Python Program to Print Square Star Pattern

Write a Python Program to Print Square Star Pattern using While Loop and For Loop with an example.

Python Program to Print Square Star Pattern using For Loop

This Python program allows users to enter any side of a square. This side decides the total number of rows and columns of a square. Next, this program uses For Loop to print stars until it reaches to the user-specified rows and columns.

# Python Program to Print Square Star Pattern
 
side = int(input("Please Enter any Side of a Square  : "))

print("Square Star Pattern") 

for i in range(side):
    for i in range(side):
        print('*', end = '  ')
    print()
Python Program to Print Square Star Pattern 1

Python Program to Display Square Star Pattern using While Loop

In this Python program, we just replaced the For Loop with While Loop.

# Python Program to Print Square Star Pattern
 
side = int(input("Please Enter any Side of a Square  : "))
i = 0
print("Square Star Pattern") 

while(i < side):
    j = 0
    while(j < side):      
        j = j + 1
        print('*', end = '  ')
    i = i + 1
    print('')
Please Enter any Side of a Square  : 12
Square Star Pattern
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  
>>> 

Python Program to Display Square Star Pattern

In this Python program, we replaced the star with a $ symbol. So, it prints the dollar until it reaches to user-specified rows and columns.

# Python Program to Print Square Star Pattern
 
side = int(input("Please Enter any Side of a Square  : "))

print("Square Star Pattern") 

for i in range(side):
    for i in range(side):
        print('$', end = '  ')
    print()
Please Enter any Side of a Square  : 15
Square Star Pattern
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  $  $  $  
>>> 

Comments are closed.