PTA乙1027打印沙漏(Python3)

n, s = input().split()
n = int(n)
f, i = 1, 1
str_ = [s]
while True:
    now = i * 2 + 1
    f = f + now *2
    if f > n:
        break
    else:
        str_.insert(0, now*s)
        str_.insert(i * 2, now*s)
    i = i + 1
k = n - (f - now*2)
j = i
for t in str_[ : i]:
    t = (i - j) * ' ' + t
    print(t)
    j = j - 1
j = j + 2
for t in str_[i : ]:
    t = (i - j) * ' ' + t
    print(t)
    j = j + 1
print(k)

猜你喜欢

转载自blog.csdn.net/AK47red/article/details/89918938