每行可以缩进
len(row) - i
然后对每个字符进行空格,使每行的长度是原来的两倍,以平衡其他正确的对齐方式。
inc = int(input('Input number of rows: '))
n = 0
row = []
while n <= inc:
m = 11 ** n
row.append(m)
n += 1
for i in range(0, len(row)):
indent = " " * (len(row) - i)
spaced_row = " ".join(list(str(row[i])))
row[i] = indent + spaced_row
result = '\n'.join(row)
print(result)
输出
Input number of rows: 3
1
1 1
1 2 1
1 3 3 1