def substitute(text, mapping, case_sensitive=False):
    """Swap characters in text as specified in the mapping

    Args:
        text (str): initial un-substituted text 
        mapping ({char -> char}): mapping of swapped characters like:
                                  A\tZ
                                  B\tY
                                  C\tX

        case_sensitive (bool, optional): set text to upper if false
                                         defaults to false

    Returns:
        str: text after letter substitutions have been made
    """
    if not case_sensitive:
        text = text.upper()

    new_text = ""
    
    for letter in text:
        if letter in mapping:
            new_text += mapping[letter]
        else:
            new_text += letter

    return new_text