Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merry Xmas
#1
"""
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
Reply
#2
Merry Xmas to you as well.
Reply
#3
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merry Christmas DeaD_EyE 4 5,675 Dec-25-2017, 02:02 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020