Fundamentals 3 min read

Create a Super‑Simple Python Christmas Tree in 6 Lines

This short tutorial shows how to draw an ASCII Christmas tree in the console using just six lines of Python code, explaining each variable, the loop logic, and how to add a simple trunk.

Coder Trainee
Coder Trainee
Coder Trainee
Create a Super‑Simple Python Christmas Tree in 6 Lines

Python Christmas Tree

First, define the tree height. The variable height is set to 8, which means the tree will have eight rows.

Next, set the initial number of snowflake characters. The variable snowflake starts at 1.

The core of the program is a for loop that runs height times. In each iteration the code prints a line consisting of spaces followed by a number of asterisks ( *) that represent snowflakes. The number of leading spaces is height - i to center the tree, and the number of asterisks is the current value of snowflake. After printing a line, snowflake is increased by 2 so the next line becomes wider, forming the triangular shape of the tree.

Finally, the trunk is printed. Three identical lines are output, each consisting of height spaces followed by a vertical bar ( |). The trunk lines can be omitted for an even shorter version.

height = 8
snowflake = 1
for i in range(height):
    print((' ' * (height - i)) + ('*' * snowflake))
    snowflake += 2
print((' ' * height) + '|')
print((' ' * height) + '|')
print((' ' * height) + '|')

The article notes that Python’s syntax is concise: variables do not need explicit type declarations, and statements do not require trailing semicolons. This makes the example especially approachable for beginners.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonLoopsBeginnerASCII artConsole output
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.