{"record":{"id":"055b61233c10f795","repo":"TheAlgorithms/Python","slug":"only-integers-accepted-as-input","errorCode":null,"errorMessage":"only integers accepted as input","messagePattern":"only integers accepted as input","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"maths/remove_digit.py","lineNumber":25,"sourceCode":"\n    >>> remove_digit(152)\n    52\n    >>> remove_digit(6385)\n    685\n    >>> remove_digit(-11)\n    1\n    >>> remove_digit(2222222)\n    222222\n    >>> remove_digit(\"2222222\")\n    Traceback (most recent call last):\n    TypeError: only integers accepted as input\n    >>> remove_digit(\"string input\")\n    Traceback (most recent call last):\n    TypeError: only integers accepted as input\n    \"\"\"\n\n    if not isinstance(num, int):\n        raise TypeError(\"only integers accepted as input\")\n    else:\n        num_str = str(abs(num))\n        num_transpositions = [list(num_str) for char in range(len(num_str))]\n        for index in range(len(num_str)):\n            num_transpositions[index].pop(index)\n        return max(\n            int(\"\".join(list(transposition))) for transposition in num_transpositions\n        )\n\n\nif __name__ == \"__main__\":\n    __import__(\"doctest\").testmod()\n","sourceCodeStart":7,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/remove_digit.py#L7-L38","documentation":"remove_digit() in maths/remove_digit.py computes the largest number obtainable by deleting one digit from num. It requires isinstance(num, int) and raises TypeError('only integers accepted as input') otherwise, because it does str(abs(num)) and builds digit-transposition lists — a non-int either breaks str/abs or produces character slices that int() cannot reparse. This function correctly uses TypeError (unlike several siblings that use ValueError).","triggerScenarios":"Calling remove_digit('2222222') or remove_digit('string input'); any call forwarding input() text, a web-parameter string, or a float like 2222222.0 without conversion.","commonSituations":"Passing request/form values (always strings) directly; JSON data where the number arrived as a string; assuming the function parses text because its doctests show digit strings in error cases.","solutions":["Convert the value first: remove_digit(int(num)) after confirming it is numeric.","Parse and validate strings at the edge (int(text) in try/except ValueError) and pass the int.","Catch TypeError (this function's contract) rather than ValueError."],"exampleFix":"# before\nremove_digit(form_value)  # TypeError when form_value is '2222222'\n\n# after\nremove_digit(int(form_value))","handlingStrategy":"type-guard","validationCode":"if not isinstance(num, int):\n    num = int(num)\nremove_digit(num)","typeGuard":"def is_strict_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":"try:\n    remove_digit(num)\nexcept TypeError:\n    num = int(num)  # this function raises TypeError, unlike siblings","preventionTips":["int() every form/request value before math helpers.","This module uses TypeError; the persistence/prime modules use ValueError — check each contract.","Keep parsing at the boundary, math inside."],"tags":["python","type-error","input-validation","maths"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}