<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode_chr(chromosome):
 """Encodes chromosomes. :param chromosome: the chromosome to encode. :type chromosome: str :returns: the encoded chromosome as :py:class:`int`. It changes ``X``, ``Y``, ``XY`` and ``MT`` to ``23``, ``24``, ``25`` and ``26``, respectively. It changes everything else as :py:class:`int`. If :py:class:`ValueError` is raised, then :py:class:`ProgramError` is also raised. If a chromosome as a value below 1 or above 26, a :py:class:`ProgramError` is raised. .. testsetup:: from pyGenClean.SexCheck.gender_plot import encode_chr .. doctest:: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [11, 12, 13, 14, 15, 16, 17, 18, 19, 20] [21, 22, 23, 24, 25, 26] [23, 24, 25, 26] Traceback (most recent call last):
 ProgramError: 27: invalid chromosome Traceback (most recent call last):
 ProgramError: XX: invalid chromosome """

    if chromosome == "X":
        return 23
    if chromosome == "Y":
        return 24
    if chromosome == "XY":
        return 25
    if chromosome == "MT":
        return 26
    try:
        new_chromosome = int(chromosome)
        if new_chromosome < 0 or new_chromosome > 26:
            msg = "{}: invalid chromosome".format(chromosome)
            raise ProgramError(msg)
        return new_chromosome
    except ValueError:
        msg = "{}: invalid chromosome".format(chromosome)
        raise ProgramError(msg)