我用遍历二维数组做出来的,楼上用append做出来实在佩服啊

n = int(input())
a = [[1 for _ in range(n)] for _ in range(n)]
for i in range(0,n):
    for j in range(0,i+1):
        if(j == 0 or i == 0 or i==j):
            a[i][j]==1
        else:
            a[i][j]= a[i-1][j-1]+a[i-1][j]
    
for i in range(0,n):
    for j in range(0,i+1):

            print(f"{a[i][j]:5d}" ,end="")
       
    print()