import re


def n_credit(sentence):
    """
    If a phrase in the form "X credit" appears in the sentence, and
    X is a number, add a hyphen to "credit".
    If "X-credit" appears, split it into "X" and "-credit".
    Do not hyphenate "X credits" or "Y credit" where Y is not a number.
    Run this after the tokenized text has been joined.
    >>> n_credit('I need a 3 credit course .')
    'I need a 3 -credit course .'
    >>> n_credit('I need a 3-credit course .')
    'I need a 3 -credit course .'
    >>> n_credit('I need a course worth 3 credits .')
    'I need a course worth 3 credits .'
    >>> n_credit('Can I get credit ?')
    'Can I get credit ?'
    """
    pattern = r"(?P<number>\d)+[- ]credit\s"
    repl = r"\g<number> -credit "
    return re.sub(pattern, repl, sentence)