编写一个Python程序,使用for循环来打印倒三角数字模式。
rows = int(input("Enter Inverted Triangle Number Pattern Rows = "))
print("====倒三角数字图案====")
for i in range(1, rows + 1): for j in range(1, i): print(end = ' ') for k in range(1, rows - i + 2): print(k, end = ' ') print()
这个Python例子使用while循环显示数字的倒三角模式。
# Python程序使用while循环来打印倒三角数字图案 rows = int(input("Enter Rows = ")
print("========") i = 1
while(i <= rows): j = 1 while(j < i): print(end = ' ') j = j + 1 k = 1 while(k <= rows - i + 1): print(k, end = ' ') k = k + 1 print() i = i + 1
Enter Rows = 13
========
1 2 3 4 5 6 7 8 9 10 11 12 13
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1