编程语言
首页 > 编程语言> > 算法——三角形图形

算法——三角形图形

作者:互联网

三角形图形

# 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)

标签:__,end,whitespace,asterisk,算法,print,图形,三角形,row
来源: https://www.cnblogs.com/noonjuan/p/11119637.html