算法——三角形图形

三角形图形

# triangle.py
def triangle(n: int) -> None:
    row = n
    for i in range(row-1):
        # asterisk & new line
        print('*' * (i+1), end='')
        # whitespace
        print(' ' * (n-i-1), end='')
        # whitespace
        print(' ' * (row-i-1), end='')
        # asterisk & new line
        print('*' * (i+1))
    for i in range(row):
        # asterisk 
        print('*' * (row - i), end='')
        # whitespace
        print(' ' * (i), end='')
        # whitespace
        print(' ' * (i), end='')
        # asterisk & new line
        print('*' * (row - i))



if __name__ == '__main__':
    triangle(20)

posted @ 2019-07-02 11:41  no樂on  阅读(353)  评论(0编辑  收藏  举报