算法——星星树
星星树
def tree(n: int) -> None: widest = 1 for i in range(n-1): widest += 2 for row in range(1, n+1): print(' ' * (widest // 2 - row + 1), '*' * ((row-1)*2+1), sep='') for row in range(1, n+1): print(' ' * (widest // 2 ), '*', sep='') height = int(input('Enter the height of the tree: ')) tree(height)
Resistance is Futile!