[每日一题] 01.23 - 画矩形

画矩形

[每日一题] 01.23 - 画矩形_第1张图片

height,width,c,d = input().split()
height,width,d = int(height),int(width),int(d)
lis = [c * width if d else c + ' ' * (width - 2) + c for i in range(height) ]
'''
lis:
#####
#   #
#   #
#####
或
#   #
#   #
#   #
#   #
'''
if not d:
    print(c * width)
    for i in lis[1:-1]:
        print(i)
    print(c * width)
else:
    for i in lis:
        print(i)

或者:

height,width,c,d = input().split()
height,width,d = int(height),int(width),int(d)

for i in range(height):
    if i == 0 or i == height - 1:
        print(c * width)
    else:
        if d == 0:
            print(c + ' ' * (width - 2) + c)
        else:
            print(c * width)

你可能感兴趣的:(算法,python,python,算法)