the key to programming is looking for patterns, and then implementing them.
define your requirements:
• must have fixed-space fonts
• border at the top/bottom needs to be the length of text + margin (white space) + border
• text must have two spaces in all directions (vertical and horizontal)
• you want alternating periods and hyphens
def spaced(s):
text = "hello"
textLength = len(text)
lineLength = textLength + 2 * (2 + 1)
height = 5
# at this point we know the first and fifth lines are the same and
# we know the first and fourth are the same. (reflected against the x-axis)
hBorder = ""
for c in range(lineLength):
if c % 2:
hBorder = hBorder + '.'
else:
hBorder = hBorder + '-'
spacer = "." + " " * (lineLength - 2) + "."
fancyText = "- " + text + " -"
return (hBorder, spacer, fancyText, spacer, hBorder)
textTuple = spaced("hello world")
for line in textTuple:
print line
Remember, you can only predict spacing for fixed width fonts. If you have any questions about the function above, ask in the comments. Cheers.