Create an ASCII Christmas Tree with Shell and Python Scripts
This article shares a festive greeting and demonstrates how to generate an ASCII Christmas tree using both a Bash shell script and a Python program, followed by details about the upcoming GOPS Global Operations Conference in Shenzhen, encouraging operations professionals to celebrate the holiday season.
Hello, dear friends! As the beautiful scenery of Jiangnan arrives and blossoms fall, the annual Christmas season is approaching.
We ask: why shouldn't operations engineers celebrate Christmas? Today we’ll draw a Christmas tree with code.
Shell Script Version
<code>#!/bin/bash
declare -a a=('.' '~' "'" 'O' "'" '~' '.' '*')
[[ $# = 0 ]] && s=9 || s=$1
[[ $s -gt 5 ]] || s=5
for (( w=1, r=7, n=1; n<=$s; n++ )) ; do
for (( i=$s-n; i>0; i-- )) ; do
echo -n " "
done
for (( i=1; i<=w; i++ )) ; do
echo -n "${a[r]}"
[[ $r -gt 5 ]] && r=0 || r=$r+1
done
w=$w+2
echo " "
done; echo " "
</code>Python Code Version
<code>import sys
w = sys.stdout.write
def t(n,s):
for i in range(n):
for a in range(n-i):
w(" ")
w("[")
for l in range(i<<1):
if i==n-1:
w("_")
else:
w("~")
w("]")
print("")
for o in range(s):
for i in range(n):
w(" ")
print("[]")
t(10, 2)
</code>The script prints a stylized Christmas tree directly in the terminal.
Upcoming GOPS Global Operations Conference
The GOPS Global Operations Conference, co‑hosted by GreatOPS and BizDevOps, will be held in Shenzhen on April 25‑26, 2025. It is the first large‑scale operations conference in China, gathering thousands of professionals to share advanced technologies and best practices.
Wishing all operations engineers a happy holiday!
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
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.