;

Python Program to Print the Square Pattern of Numbers


Tutorialsrack 16/05/2020 Python

In this python program, we will learn how to print the square pattern of numbers.

Here is the source code of the program to print the square pattern of numbers.

Program 1: Python Program to Print the Square Pattern of Numbers Using For Loop

Python Program to Print the Square Pattern of Numbers Using For Loop
# Python Program to Print the Square Pattern of Numbers
# Using For Loop

# Take the Input From the User5
side = int(input("Enter any Side of a Square: "))

# Print the Output
print("Square Pattern of Number") 

for i in range(side):
    for i in range(side):
        print('1', end = '  ')
    print()
Output

Enter any Side of a Square: 5

Square Pattern of Number

1  1  1  1  1  

1  1  1  1  1  

1  1  1  1  1  

1  1  1  1  1  

1  1  1  1  1

Program 2: Python Program to Print the Square Pattern of Numbers Using While Loop

Python Program to Print the Square Pattern of Numbers Using While Loop
# Python Program to Print the Square Pattern of Numbers
# Using While Loop

# Take the Input From the User5
side = int(input("Enter any Side of a Square: "))

i = 0
# Print the Output
print("Square Pattern of Number") 

while(i < side):
    j = 0
    while(j < side):      
        j = j + 1
        print('1', end = '  ')
    i = i + 1
    print('')  
Output

Enter any Side of a Square: 6

Square Pattern of Number

1  1  1  1  1  1  

1  1  1  1  1  1  

1  1  1  1  1  1  

1  1  1  1  1  1  

1  1  1  1  1  1  

1  1  1  1  1  1


Related Posts



Comments

Recent Posts
Tags