0% found this document useful (0 votes)
13 views3 pages

Christmas Tree

Uploaded by

Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Christmas Tree

Uploaded by

Tesfaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

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 = turtle.Screen()

window.bgcolor("sky blue")

tree = turtle.Turtle()

tree.color("forest green")

def make_tree_segment(size, top_position):

tree.begin_fill()

tree.setposition(0, top_position)

tree.setposition(size, top_position - size)

tree.setposition(-size, top_position - size)

tree.setposition(0, top_position)

tree.end_fill()

for size, top_position in tree_segments:

make_tree_segment(size, top_position)

turtle.done()

You might also like