def apply_case(s, case):
    """Helper function that applies case to a string."""

    if case.upper() == "UPPER":
        s = s.upper()
    elif case.upper() == "LOWER":
        s = s.lower()
    elif case.upper() == "CAPITALIZE":
        s = s.capitalize()
    elif case.upper() == "TITLE":
        s = " ".join([w.capitalize() for w in s.split(" ")])
    return s