Python 打印左旋奇数方阵程序

编写一个 Python 程序,使用 for 循环打印左旋奇数方阵。

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

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

for i in range(1, rows + 1):
    for j in range(i - 1, rows):
        print(j * 2 + 1, end = ' ')
    for k in range(0, i - 1):
        print(k * 2 + 1, end = ' ')
    print()
Python Program to Print Square Pattern of Left Rotating Odd Numbers

这是另一种编写 Python 程序的方法,用于打印从上到下左移的奇数方阵。

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

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

for i in range(1, rows + 1):
    j = i * 2 - 1
    for k in range(1, rows + 1):
        print(j, end = ' ')
        j = j + 2
        if j > rows * 2 - 1:
            j = 1
    print()
Enter Square of Left Shift Odd Numbers Rows = 9
====The Square Pattern of Left Shift Odd Numbers====
1 3 5 7 9 11 13 15 17 
3 5 7 9 11 13 15 17 1 
5 7 9 11 13 15 17 1 3 
7 9 11 13 15 17 1 3 5 
9 11 13 15 17 1 3 5 7 
11 13 15 17 1 3 5 7 9 
13 15 17 1 3 5 7 9 11 
15 17 1 3 5 7 9 11 13 
17 1 3 5 7 9 11 13 15 

此 Python 示例 使用 while 循环显示左旋或左移的奇数方阵。

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

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

i = 1

while(i <= rows):
    j = i - 1
    while(j < rows):
        print(j * 2 + 1, end = ' ')
        j = j + 1
    k = 0
    while(k < i - 1):
        print(k * 2 + 1, end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Square of Left Shift Odd Numbers Rows = 13
====The Square Pattern of Left Shift Odd Numbers====
1 3 5 7 9 11 13 15 17 19 21 23 25 
3 5 7 9 11 13 15 17 19 21 23 25 1 
5 7 9 11 13 15 17 19 21 23 25 1 3 
7 9 11 13 15 17 19 21 23 25 1 3 5 
9 11 13 15 17 19 21 23 25 1 3 5 7 
11 13 15 17 19 21 23 25 1 3 5 7 9 
13 15 17 19 21 23 25 1 3 5 7 9 11 
15 17 19 21 23 25 1 3 5 7 9 11 13 
17 19 21 23 25 1 3 5 7 9 11 13 15 
19 21 23 25 1 3 5 7 9 11 13 15 17 
21 23 25 1 3 5 7 9 11 13 15 17 19 
23 25 1 3 5 7 9 11 13 15 17 19 21 
25 1 3 5 7 9 11 13 15 17 19 21 23