cht="Happy Christmas"
print(cht)
for leaf in [*range(10)] + [2]:
print(f'{"X"*(leaf*2+1):^30}')
Output
Happy Christmas
XXX
XXXXX
XXXXXXX
XXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXX
XXXXX
# Number of levels for the Christmas tree
num = 3
# First Level of Leaves
for i in range(1, num + 1):
# Print spaces to center the stars
print(" " * (2 * num - i + 3), end="")
# Print stars with a space in between
for j in range(1, i + 1):
print("*", end=" ")
# Move to the next line after printing stars
print()
# Second Level of Leaves
for i in range(1, num + 3):
print(" " * (2 * num - i + 1), end="")
for j in range(-1, i + 1):
print("*", end=" ")
print()
# Third Level of Leaves (Optional for larger trees)
for i in range(1, num + 5):
print(" " * (2 * num - i), end="")
for j in range(-2, i + 1):
print("*", end=" ")
print()
# Trunk of the Tree
for i in range(1, num + 3):
# Print spaces to center the trunk
print(" " * (2 * num), end="")
# Print the trunk (3 stars)
print("* " * 3)
import turtle
tree_segments = ((50, 20), (80, 0), (120, -30), (150, -60))
window = [Link]()
[Link]("sky blue")
tree = [Link]()
[Link]("forest green")
def make_tree_segment(size, top_position):
tree.begin_fill()
[Link](0, top_position)
[Link](size, top_position - size)
[Link](-size, top_position - size)
[Link](0, top_position)
tree.end_fill()
for size, top_position in tree_segments:
make_tree_segment(size, top_position)
[Link]()