""" Examples of recursion on stings from Lec 18
"""

def reverse(s):
    """
    Returns: s with its characters in reverse order

    Parameter: s the string to reverse
    Precondition s is a string
    """
    # Work on small data  (BASE CASE)
    if len(s)<=1:
        return s

    # Break up the data   (RECUSIVE CASE)
    left  = reverse(s[0])  # Reverse of one letter is itself
    right = reverse(s[1:])

    # Combine the results
    return right+left

def ispalindrome(s):
    """
    Returns: True if s is a palindrome; False otherwise.

    Parameter: s is the string to check whether it is a ispalindrome
    Precondition: s is a string
    """
    # Work on small data  (BASE CASE)
    if len(s)<2:       # Base case
        return True

    # Break up the data   (RECUSIVE CASE)
    ends= s[0]==s[-1]
    middle= ispalindrome(s[1:-1])
    return ends and middle


print("Reverse the string 'Hello':")
print(reverse('Hello!'))

print("Is 'mom' a palindrome?")
if ispalindrome('mom'):
    print('yes')
else:
    print('no')
