I'm working on this Python task that I can't figure out. It is the last of 3 functions and the first 2 were much easier to program then this one. The instructions are "Given a message that may contain multiple lines, utilize the split() function to identify the individual lines, and the format() function so that when printed, it draws a box around the message's lines, all centered. Box uses vertical bars & dashes on the sides (|, -), +'s in the corners (+), and there is always a column of spaces to the left and right of the widest line of the message."
Some examples for what this function needs to do:
test that: border_msg('a') == '+---+\n| a |\n+---+\n'
test that: border_msg('hello') == '+-------+\n| hello |\n+-------+\n'
test that: border_msg("hi!\nhow are you?\ndrive safely!") == '+---------------+\n| hi! |\n| how are you? |\n| drive safely! |\n+---------------+\n'
I think it needs to print the above tests so that the words in the middle are surrounded by the "+------+ on the top and bottom and "|"'s on the sides.
Here is the code I have so far. I'm not sure where I would go from here.
def border_msg(msg):
border_msg.split("\n")
'%s'.format(msg)
return border_msg(msg)
print border_msg(msg)