Python Forum
Merry Xmas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: Merry Xmas (/thread-23370.html)



Merry Xmas - ichabod801 - Dec-25-2019

"""
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))



RE: Merry Xmas - Larz60+ - Dec-25-2019

Merry Xmas to you as well.


RE: Merry Xmas - snippsat - Dec-25-2019

def christmas(word, numb):
    return f'  \N{tear-off calendar}  '.join([f'{word.capitalize():\N{Christmas tree}^21}'] * numb)

print(christmas('merry christmas', 2))
[Image: DIStA7.png]