code

row = int(input("请输入行数:"))
num = 1
sum = 0
for i in range(1, row + 1):
    for j in range(row - i, 0, -1):
        print(" ", end="\t")

    for j in range(1, i + 1):
        print(num, end="\t")
        num *= 2
        sum = num
    num = 1
    sum //= 2
    for j in range(2, i + 1):
        print(sum//2, end="\t")
        sum //= 2

    print("")

 

python 生成金字塔,2^n_Python