Last active
September 26, 2018 05:51
-
-
Save ChiaraHsieh/2ab52f17c067ffa1d08c90db01a9c58b to your computer and use it in GitHub Desktop.
asterisk Christmas tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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