Python程序打印乘法数字的右帕斯卡三角形图案

322 阅读1分钟

编写一个Python程序,使用for循环来打印右帕斯卡乘法数的三角形。

rows = int(input("Enter Right Pascals Multiplication Number Triangle Rows = " ))

print("==== 右帕斯卡乘法数字三角形图案====")

for i in range(1, rows + 1): for j in range(1, i + 1): print(j \* i, end = ' ' ) print()

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

image.png

这个Python例子使用while循环打印乘法数字的右帕斯卡三角形模式。

rows = int(input("Enter Right Pascals Multiplication Number Triangle Rows = "))

print("====Right Pascals Triangle of Multiplication Numbers Pattern====")
i = 1

while(i <= rows):
    j = 1
    while(j <= i):
        print(i \* j, end = ' ')
        j = j + 1
    print()
    i = i + 1

i = rows - 1
while(i >= 1):
    j = 1
    while(j <= i):
        print(i \* j, end = ' ')
        j = j + 1
    print()
    i = i - 1
    Enter Right Pascals Multiplication Number Triangle Rows = 12
    ====Right Pascals Triangle of Multiplication Numbers Pattern====
    1 
    2 4 
    3 6 9 
    4 8 12 16 
    5 10 15 20 25 
    6 12 18 24 30 36 
    7 14 21 28 35 42 49 
    8 16 24 32 40 48 56 64 
    9 18 27 36 45 54 63 72 81 
    10 20 30 40 50 60 70 80 90 100 
    11 22 33 44 55 66 77 88 99 110 121 
    12 24 36 48 60 72 84 96 108 120 132 144 
    11 22 33 44 55 66 77 88 99 110 121 
    10 20 30 40 50 60 70 80 90 100 
    9 18 27 36 45 54 63 72 81 
    8 16 24 32 40 48 56 64 
    7 14 21 28 35 42 49 
    6 12 18 24 30 36 
    5 10 15 20 25 
    4 8 12 16 
    3 6 9 
    2 4 
    1