def parse_color_string(color_string):
    """
    Parses a string a user typed into a tuple of 3 integers representing the
    red, green and blue channels respectively.

    May raise a ValueError if the string cannot be parsed.

    The colour string must be a CSS 3 or 6 digit hex code without the '#' prefix.
    """
    if len(color_string) == 3:
        r = int(color_string[0], 16) * 17
        g = int(color_string[1], 16) * 17
        b = int(color_string[2], 16) * 17
    elif len(color_string) == 6:
        r = int(color_string[0:2], 16)
        g = int(color_string[2:4], 16)
        b = int(color_string[4:6], 16)
    else:
        raise ValueError("Color string must be either 3 or 6 hexadecimal digits long")

    return r, g, b