Skip to content

Instantly share code, notes, and snippets.

@ChiaraHsieh
Last active September 26, 2018 05:51
Show Gist options
  • Save ChiaraHsieh/2ab52f17c067ffa1d08c90db01a9c58b to your computer and use it in GitHub Desktop.
Save ChiaraHsieh/2ab52f17c067ffa1d08c90db01a9c58b to your computer and use it in GitHub Desktop.
asterisk Christmas tree
# 9-24-2018 by Chiara Hsieh
# Draw a Christmas tree with this code snippet
import sys
def tree_chunk(width, bottom, top):
for i in range(bottom, top, 2):
spaces=(width-i)/2
for j in range(spaces):
sys.stdout.write (' ')
for j in range(i):
sys.stdout.write ('*')
for j in range(spaces):
sys.stdout.write(' ')
sys.stdout.write('\n')
total_width=21
tree_chunk(total_width,1,9)
tree_chunk(total_width,5,13)
tree_chunk(total_width,9,19)
tree_chunk(total_width,3,5)
tree_chunk(total_width,3,5)
tree_chunk(total_width,3,5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment