Python Program to Print Christmas Tree Star Pattern

Write a Python program to print Christmas tree star pattern using for loop.

width = int(input("Enter Chirstmas Tree Width   = "))
height = int(input("Enter Chirstmas Tree Height = "))

space = width * height
n = 1

print("====The Chirstmas Tree Star Pattern====")
alphabet = 65

for x in range(1, height + 1):
    for i in range(n, width + 1):
        for j in range(space, i - 1, -1):
            print(end = ' ')
        for k in range(1, i + 1):
            print('*', end = ' ')
        print()
    n = n + 2
    width = width + 2

for i in range(1, height):
    for j in range(space - 3, -1, -1):
        print(end = ' ')
    for k in range(1, height):
        print('*', end = ' ')
    print()
Python Program to Print Christmas Tree Star Pattern

This Python example prints the Christmas tree pattern of stars using a while loop.

width = int(input("Enter Christmas Tree Width   = "))
height = int(input("Enter Christmas Tree Height = "))

space = width * height
n = 1

print("====The Christmas Tree Star Pattern====")
alphabet = 65
x = 1

while(x <= height):
    i = n
    while(i <= width):
        j = space
        while(j >= i):
            print(end = ' ')
            j = j - 1
        k = 1
        while(k <= i):
            print('*', end = ' ')
            k = k + 1
        print()
        i = i + 1
    n = n + 2
    width = width + 2
    x = x + 1

i = 1
while(i < height):
    j = space - 3
    while(j >= 0):
        print(end = ' ')
        j = j - 1
    k = 1
    while(k < height):
        print('*', end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Christmas Tree Width   = 7
Enter Christmas Tree Height = 5
====The Christmas Tree Star Pattern====
                                   * 
                                  * * 
                                 * * * 
                                * * * * 
                               * * * * * 
                              * * * * * * 
                             * * * * * * * 
                                 * * * 
                                * * * * 
                               * * * * * 
                              * * * * * * 
                             * * * * * * * 
                            * * * * * * * * 
                           * * * * * * * * * 
                               * * * * * 
                              * * * * * * 
                             * * * * * * * 
                            * * * * * * * * 
                           * * * * * * * * * 
                          * * * * * * * * * * 
                         * * * * * * * * * * * 
                             * * * * * * * 
                            * * * * * * * * 
                           * * * * * * * * * 
                          * * * * * * * * * * 
                         * * * * * * * * * * * 
                        * * * * * * * * * * * * 
                       * * * * * * * * * * * * * 
                           * * * * * * * * * 
                          * * * * * * * * * * 
                         * * * * * * * * * * * 
                        * * * * * * * * * * * * 
                       * * * * * * * * * * * * * 
                      * * * * * * * * * * * * * * 
                     * * * * * * * * * * * * * * * 
                                 * * * * 
                                 * * * * 
                                 * * * * 
                                 * * * * 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.