编写一个Python程序,使用for循环来打印金字塔数字模式。
rows = int(input("Enter Numbers Pyramid Pattern Rows = "))
print("====The Pyramid of Numbers Pattern====")
for i in range(1, rows + 1): for j in range(rows, i, -1): print(end = ' ') for k in range(1, i + 1): print(i, end = ' ') print()
这个Python例子使用一个while循环来打印金字塔模式的数字。
# Python程序使用while循环来打印金字塔数字模式 rows = int(input("Enter Rows = ")
print("========") i = 1
while(i <= rows): j = rows while(j > i): print(end = ' ') j = j - 1 k = 1 while(k <= i): print(i, end = ' ') k = k + 1 print() I = i + 1
Enter Rows = 9
========
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9