下面是用 Python 实现的一个简单的圣诞树代码:
def christmas_tree(height):
for i in range(1, height + 1):
spaces = height - i
stars = 2 * i - 1
print(" " * spaces + "*" * stars)
christmas_tree(10)
代码实现了一个打印圣诞树的函数 christmas_tree
,您可以指定圣诞树的高度,函数会根据高度生成相应的圣诞树图形。