Python程序打印左减数的平方图案

101 阅读1分钟

编写一个Python程序,使用for循环来打印左减数的平方。

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

print("====The Square Left Decrement Numbers Pattern====")

for i in range(rows, 0, -1): for j in range(i, rows): print(j, end = ' ') for k in range(rows - i, rows): print(rows, end = ' ') print()

image.png

这个Python程序使用一个while循环显示从左边开始递减数字的正方形图案。

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

print("====The Square Left Decrement Numbers Pattern====") i = rows

while(i >= 1): j = i while(j < rows): print(j, end = ' ') j = j + 1 k = rows - i while(k < rows): print(rows, end = ' ') k = k + 1 print() i = i - 1
Enter Square of Left Decrement Numbers Rows = 9
====The Square Left Decrement Numbers Pattern====
9 9 9 9 9 9 9 9 9 
8 9 9 9 9 9 9 9 9 
7 8 9 9 9 9 9 9 9 
6 7 8 9 9 9 9 9 9 
5 6 7 8 9 9 9 9 9 
4 5 6 7 8 9 9 9 9 
3 4 5 6 7 8 9 9 9 
2 3 4 5 6 7 8 9 9 
1 2 3 4 5 6 7 8 9