Untitled

Run Settings
LanguagePython
Language Version
Run Command
def print_christmas_tree(height): """ Prints a text-based Christmas tree of a given height. The height determines the number of rows for the tree's branches. """ # Print the tree's branches for i in range(height): # Calculate leading spaces for centering spaces = " " * (height - i - 1) # Calculate stars for the current row stars = "*" * (2 * i + 1) print(spaces + stars) # Print the tree's trunk # The trunk height is typically a small, fixed number of rows trunk_height = 2 for _ in range(trunk_height): # Center the trunk based on the tree's base width trunk_spaces = " " * (height - 1) print(trunk_spaces + "|") # Example usage: print_christmas_tree(5) print("\nMerry Christmas!")
Editor Settings
Theme
Key bindings
Full width
Lines