Python Program to Print Same Numbers in Square Rows and Columns

Write a Python program to print the same numbers in square number pattern rows and columns using for loop.

rows = int(input("Enter Same Number Rows & Columns Square Pattern Rows = "))

print("===Printing Same Number in Rows and Columns of a Square Pattern===")

for i in range(1, rows + 1):
    for j in range(i, rows + 1):
        print(j, end = ' ')
    for k in range(1, i):
        print(k, end = ' ')
    print()
Python Program to Print Same Numbers in Square Rows and Columns

This Python example prints the square number pattern where rows and columns have the same numbers using a while loop.

rows = int(input("Enter Same Number Rows & Columns Square Pattern Rows = "))

print("===Printing Same Number in Rows and Columns of a Square Pattern===")
i = 1
while(i <= rows):

    j = i
    while(j < rows + 1):
        print(j, end = ' ')
        j = j + 1

    k = 1
    while(k < i):
        print(k, end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Same Number Rows & Columns Square Pattern Rows = 9
===Printing Same Number in Rows and Columns of a Square Pattern===
1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 1 
3 4 5 6 7 8 9 1 2 
4 5 6 7 8 9 1 2 3 
5 6 7 8 9 1 2 3 4 
6 7 8 9 1 2 3 4 5 
7 8 9 1 2 3 4 5 6 
8 9 1 2 3 4 5 6 7 
9 1 2 3 4 5 6 7 8