[Solved] Repeating Characters in the Middle of a String


def repeat_middle(text):
    a, b = divmod(len(text) - 1, 2)
    middle = text[a:a + b + 1]
    exclamations="!" * len(middle)
    return '{}{}{}'.format(exclamations, middle * len(text), exclamations)

>>> print repeat_middle("abMNcd")
!!MNMNMNMNMNMN!!

>>> print repeat_middle("abMcd")
!MMMMM!

solved Repeating Characters in the Middle of a String