画圣诞树编程码怎么画的

时间:2025-01-28 16:41:03 网络游戏

```python

def draw_christmas_tree(height):

"""

绘制圣诞树

:param height: 圣诞树的高度

"""

绘制树冠

for i in range(height):

每行的星星数量递增,前面加上空格来保持对齐

spaces = ' ' * (height - i - 1)

stars = '*' * (2 * i + 1)

print(spaces + stars)

绘制树干

trunk_width = 3

trunk_height = 2

trunk_spaces = ' ' * (height - 1)

trunk = trunk_spaces + '*' * trunk_width

for _ in range(trunk_height):

print(trunk)

def christmas_wish():

print("\n