python 实现 打印数字金字塔
count = int(input('请输入要打印的层数n:'))for i in range(count):for j in range(count - i):print(' ', end=' ')for k in range(i + 1):print(k + 1, end='')for r in range(i - 1, -1, -1):print(r + 1, end='')print()输
·
count = int(input('请输入要打印的层数n:'))
for i in range(1, count + 1):
for j in range(count - i):
print(' ', end=' ')
for k in range(1, i + 1):
print(k, end='')
for r in range(i - 1, 0, -1):
print(r, end='')
print()
输出结果如下:
更多推荐
已为社区贡献1条内容
所有评论(0)