圣诞树的编程码怎么用的

时间:2025-01-28 17:51:36 网络游戏

```python

def draw_christmas_tree(height):

"""

绘制圣诞树

参数:

height: 圣诞树的高度(即树的层数)

"""

绘制圣诞树的顶部星星

print(" " * (height - 1) + "*")

绘制圣诞树的主体部分

for i in range(1, height + 1):

print(" " * (height - i) + "*" * (2 * i - 1))

绘制圣诞树的树干

for _ in range(2):

print(" " * (height - 1) + "|")

输出节日祝福语

print("\n