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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Coder Trainee
Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
