Dec-25-2019, 05:03 PM
(This post was last modified: Dec-25-2019, 05:04 PM by ichabod801.)
"""
xmas_tree.py
Prints a tree.
Functions:
tree: Create a text representation of a tree. (str)
"""
from __future__ import print_function
import sys
def tree(width):
"""
Create a text representation of a tree. (str)
Parameters:
width: How wide the bottom of the tree should be. (int)
"""
# Make sure you have an odd width.
if width % 2 == 0:
width += 1
# Get the main section of the tree.
lines = ['']
for row_width in range(1, width + 1, 2):
lines.append(('*' * row_width).center(width))
# Print an appropriately sized trunk.
trunk_size = 3 if width > 13 else 1
for row in range(trunk_size):
lines.append(('H' * trunk_size).center(width))
return '\n'.join(lines)
if __name__ == '__main__':
# This tree goes to 11.
if len(sys.argv) > 1:
width = int(sys.argv[1])
else:
width = 11
print(tree(width))
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

![[Image: DIStA7.png]](https://imagizer.imageshack.com/v2/xq90/922/DIStA7.png)