如何打印1x3正方形图案

问题描述 投票:0回答:1

我尝试打印此问题

输入

1

3

输出enter image description here

0

def repeat(c, n)
    print(c * n)

def line():
    print('+---+')

def box(row, col):
    while row > 0:
        line()
        print('|   |')
        row = row -1
    line()




n = int(input())
m = int(input())
box(n,m)

我想像我制作的行代码一样制作“列”

python matrix design-patterns while-loop repeat
1个回答
0
投票
COLUMN = '|   '
ROW = '+---'

def box(rows, cols):
    columns = COLUMN * (cols + 1)
    row = ROW * cols + '+'
    box = []
    for i in range(rows):
        box.append(row)
        box.append(columns)
    box.append(row)
    return '\n'.join(box)

if __name__=='__main__':
    print(box(3,3))
© www.soinside.com 2019 - 2024. All rights reserved.