print a christmas tree in python

Here is a code snippet to print a Christmas tree in Python:

main.py
def print_tree(height):
    """Prints a Christmas tree of the given height."""
    for i in range(1, height+1):
        print(' '*(height-i) + '*'*(2*i-1))
    print(' '*(height-1) + '| |')
190 chars
6 lines

To print a tree of height 5, you can call the function as follows:

main.py
print_tree(5)
14 chars
2 lines

This will output:

main.py
    *
   ***
  *****
 *******
*********
    | |
48 chars
7 lines

You can modify the function to print different shapes or add decorations to the tree. Happy Coding!

gistlibby LogSnag