{"record":{"id":"3bd418bdd32fe4fb","repo":"TheAlgorithms/Python","slug":"this-function-only-converts-numbers-less-than-100","errorCode":null,"errorMessage":"This function only converts numbers less than 100","messagePattern":"This function only converts numbers less than 100","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/convert_number_to_words.py","lineNumber":124,"sourceCode":"    >>> convert_small_number(15)\n    'fifteen'\n    >>> convert_small_number(20)\n    'twenty'\n    >>> convert_small_number(25)\n    'twenty-five'\n    >>> convert_small_number(-1)\n    Traceback (most recent call last):\n    ...\n    ValueError: This function only accepts non-negative integers\n    >>> convert_small_number(123)\n    Traceback (most recent call last):\n    ...\n    ValueError: This function only converts numbers less than 100\n    \"\"\"\n    if num < 0:\n        raise ValueError(\"This function only accepts non-negative integers\")\n    if num >= 100:\n        raise ValueError(\"This function only converts numbers less than 100\")\n    tens, ones = divmod(num, 10)\n    if tens == 0:\n        return NumberWords.ONES.value[ones] or \"zero\"\n    if tens == 1:\n        return NumberWords.TEENS.value[ones]\n    return (\n        NumberWords.TENS.value[tens]\n        + (\"-\" if NumberWords.ONES.value[ones] else \"\")\n        + NumberWords.ONES.value[ones]\n    )\n\n\ndef convert_number(\n    num: int, system: Literal[\"short\", \"long\", \"indian\"] = \"short\"\n) -> str:\n    \"\"\"\n    Converts an integer to English words.\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/convert_number_to_words.py#L106-L142","documentation":"convert_small_number raises this ValueError when num >= 100. The helper only builds words for 0-99 (two tables indexed by tens and ones digits), so three-digit numbers would index the TENS table out of range or produce wrong output; the guard makes the contract explicit. Larger numbers must go through convert_number, which splits them into power-of-ten digit groups.","triggerScenarios":"convert_small_number(123); convert_small_number(100) exactly at the boundary; helper invoked recursively without convert_number's digit-group splitting.","commonSituations":"Using the helper as a general number-to-words function; copy-pasting the doctest call while adjusting the example value upward.","solutions":["Use convert_number(123) which delegates to this helper correctly","Range-check inputs: assert 0 <= num < 100 before calling","If writing a similar helper, decompose hundreds first: divmod(num, 100)"],"exampleFix":"# before\nconvert_small_number(123)\n# ValueError: This function only converts numbers less than 100\n\n# after\nconvert_number(123)  # 'one hundred twenty-three'","handlingStrategy":"validation","validationCode":"if not 0 <= num < 100:\n    raise ValueError('convert_small_number accepts 0..99 only')","typeGuard":"def is_small_non_negative(n) -> bool:\n    return isinstance(n, int) and 0 <= n < 100","tryCatchPattern":"try:\n    convert_small_number(n)\nexcept ValueError:\n    return convert_number(n)","preventionTips":["Route all user-facing calls through convert_number","Assert range in unit tests of the helper","Document the 0-99 contract wherever the helper is reused"],"tags":["conversions","numbers-to-words","validation","range-check"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}