Coding a Tree in Python

Want to try coding a simple picture during Christmas break? This is Python, so choose Python 3 for the language from the drop down in the upper right.  Note that indentation matters; the last print command (line 9) for instance is out of the ‘for’ loop above it.  Lines 1-9 define TREE and line 11 simply runs ‘tree’ as you defined it.

If you can’t figure out the exact number of spaces & underscores (lines 6 & 9), just eyeball it and give it a run.  You can always adjust/fix it afterwards and re-run it. Try different characters for x instead of * so it uses different shapes to draw with (line 2) or a different character at the end of line 6 instead of the exclamation point.

Use this website: https://www.onlinegdb.com/

 

Leave a Reply

Your email address will not be published. Required fields are marked *