python-3.x 打印给定行数的以下模式

xytpbqjk  于 2023-06-07  发布在  Python
关注(0)|答案(1)|浏览(130)

你能用python帮助打印下面的代码吗

4444444
4333334
4322234
4321234
4322234
4333334  
4444444

我尝试了下面的,但是因为我是新来的,所以对使用哪个代码有点困惑,我们如何按照下面的顺序得到数字

ubbxdtey

ubbxdtey1#

def print_pattern():
for i in range(4):
    for j in range(7):
        if abs(3 - i) <= abs(3 - j):
            print(abs(3 - i) + 1, end='')
        else:
            print(abs(3 - j) + 1, end='')
    print()
print_pattern()

相关问题