Python Program to Print Square Pattern of Left Shift Numbers

Write a Python program to print square pattern of left shift numbers using a for loop.

rows = int(input("Enter Square of Left Shift Numbers Rows = "))

print("====The Square Pattern of Left Shift Numbers====")

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 Square Pattern of Left Shift Numbers

It is another way of writing the Python program to print the square pattern of left shift numbers. For more patterns, please refer to the Python Number pattern programs.

rows = int(input("Enter Square of Left Shift Numbers Rows = "))

print("====The Square Pattern of Left Shift Numbers====")

for i in range(1, rows + 1):
    j = i
    for k in range(1, rows + 1):
        print(j, end = ' ')
        j = j + 1
        if j > rows:
            j = 1
    print()
Enter Square of Left Shift Numbers Rows = 8
====The Square Pattern of Left Shift Numbers====
1 2 3 4 5 6 7 8 
2 3 4 5 6 7 8 1 
3 4 5 6 7 8 1 2 
4 5 6 7 8 1 2 3 
5 6 7 8 1 2 3 4 
6 7 8 1 2 3 4 5 
7 8 1 2 3 4 5 6 
8 1 2 3 4 5 6 7 

This Python example displays the square pattern of left shifted numbers from top to bottom using a while loop.

rows = int(input("Enter Square of Left Shift Numbers Rows = "))

print("====The Square Pattern of Left Shift Numbers====")

i = 1

while(i <= rows):
    j = i
    while(j <= rows):
        print(j, end = ' ')
        j = j + 1
    k = 1
    while(k < i):
        print(k, end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Square of Left Shift Numbers Rows = 9
====The Square Pattern of Left Shift Numbers====
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 

Also Read