Stars

  1. Write function stars1() that takes a string and, if it has an even number of characters, returns a string equal to the given one but with two stars (asterisks) in the middle. If the given string has an odd number of characters, this function returns a string equal to the given one but with a star at the beginning and another one at the end.

    Save this function into a file named stars1.py. See the following examples:

    >>> stars1('Mary')
    'Ma**ry'
    >>> stars1('Johan')
    '*Johan*'
    >>> stars1('butterfly')
    '*butterfly*'
    >>> stars1('strawberry')
    'straw**berry'
    >>> stars1('Blood, sweat and tears')
    'Blood, swea**t and tears'
    

    Note

    More tests are provided in the test-stars1.txt file.

  2. Write function stars2() that takes a string, and returns another string computed by interleaving stars between each pair of consecutive characters of the given string.

    Save this function into a file named stars2.py. See the following examples:

    >>> stars2('Mary')
    'M*a*r*y'
    >>> stars2('Johan')
    'J*o*h*a*n'
    >>> stars2('butterfly')
    'b*u*t*t*e*r*f*l*y'
    >>> stars2('strawberry')
    's*t*r*a*w*b*e*r*r*y'
    >>> stars2('Blood, sweat and tears')
    'B*l*o*o*d*,* *s*w*e*a*t* *a*n*d* *t*e*a*r*s'
    
    

    Note

    More tests are provided in the test-stars2.txt file.

Solution

Solutions are provided in the stars1.py, stars2.py