def format_ml_code(code):
    """Checks if the ML code ends with the string 'model = ' in its last line. Otherwise, it adds the string.
        Args:
            code (str): ML code to check
        Returns:
            str: code formatted
    """

    return code[:code.rfind('\n')+1] + 'model = ' + code[code.rfind('\n')+1:]