└── Tree.py /Tree.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | tree_width = 25 4 | 5 | if len(sys.argv) is 2: 6 | tree_width = int(sys.argv[1]) 7 | if tree_width % 2 == 0: 8 | tree_width = 25 9 | 10 | def print_tree(size): 11 | # Get the string for every line of the tree 12 | def get_component(component_number): 13 | # Return None on every even number 14 | if component_number % 2 == 0: 15 | return None 16 | else: 17 | # Line is odd, print line 18 | side_width = (size - component_number) / 2 19 | return "-" * side_width + "#" * component_number + "-" * side_width 20 | 21 | # Loop through the lines and print the line 22 | for i in range(tree_width + 1): 23 | if get_component(i) is not None: 24 | print get_component(i) 25 | # Print the base 26 | print get_component(1); 27 | 28 | print_tree(tree_width) 29 | --------------------------------------------------------------------------------