diff --git a/searches/binary_tree_traversal.py b/searches/binary_tree_traversal.py index 47af57f7f94d..5e5a276f5a7a 100644 --- a/searches/binary_tree_traversal.py +++ b/searches/binary_tree_traversal.py @@ -259,6 +259,20 @@ def post_order_iter(node: TreeNode) -> None: def prompt(s: str = "", width=50, char="*") -> str: + """Return a prompt string padded to the specified width. + + >>> [prompt("Python", width=width) for width in range(8, 13)] + [' Python ', ' Python *', '* Python *', '* Python **', '** Python **'] + + >>> prompt("Python", width=40, char=chr(0x1F40D)) + '🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍 Python 🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍' + + >>> len(prompt("Python")) + 50 + + >>> prompt("Python", -200) + ' Python ' + """ if not s: return "\n" + width * char left, extra = divmod(width - len(s) - 2, 2)