{"record":{"id":"1114b56e53b5a97c","repo":"TheAlgorithms/Python","slug":"input-number-is-too-large","errorCode":null,"errorMessage":"Input number is too large","messagePattern":"Input number is too large","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/convert_number_to_words.py","lineNumber":184,"sourceCode":"    ...\n    ValueError: Input number is too large\n    >>> convert_number(10**21, \"long\")\n    Traceback (most recent call last):\n    ...\n    ValueError: Input number is too large\n    >>> convert_number(10**19, \"indian\")\n    Traceback (most recent call last):\n    ...\n    ValueError: Input number is too large\n    \"\"\"\n    word_groups = []\n\n    if num < 0:\n        word_groups.append(\"negative\")\n        num *= -1\n\n    if num > NumberingSystem.max_value(system):\n        raise ValueError(\"Input number is too large\")\n\n    for power, unit in NumberingSystem[system.upper()].value:\n        digit_group, num = divmod(num, 10**power)\n        if digit_group > 0:\n            word_group = (\n                convert_number(digit_group, system)\n                if digit_group >= 100\n                else convert_small_number(digit_group)\n            )\n            word_groups.append(f\"{word_group} {unit}\")\n    if num > 0 or not word_groups:  # word_groups is only empty if input num was 0\n        word_groups.append(convert_small_number(num))\n    return \" \".join(word_groups)\n\n\nif __name__ == \"__main__\":\n    import doctest\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/convert_number_to_words.py#L166-L202","documentation":"convert_number raises this ValueError when the (absolute) input exceeds the largest value expressible in the chosen numbering system: NumberingSystem.max_value(system). The limit is 10^18-1 style bounds computed from the largest scale word — short scale tops out after decillion, long scale one power-of-1000 higher, and the Indian system at 10^19-1 (shankh). Beyond that there are no scale words, so output would be wrong.","triggerScenarios":"convert_number(10**19, 'indian') (exactly one past the max), convert_number(10**63, 'short'), convert_number(10**63, 'long') depending on table bounds; feeding 64-bit unsigned maxima or financial aggregates in obscure units.","commonSituations":"Formatting random/big test integers without bounds; assuming all systems share the same limit; unit tests that use round power-of-ten boundaries which are exactly one above max_value.","solutions":["Check abs(num) <= NumberingSystem.max_value(system) before calling","Switch to a system with a higher cap (long > short for equal word counts) if semantics allow","Reject or clamp such inputs at your API boundary and report them to the user"],"exampleFix":"# before\nconvert_number(10**19, 'indian')\n# ValueError: Input number is too large\n\n# after\nfrom conversions.convert_number_to_words import NumberingSystem\nif abs(n) > NumberingSystem.max_value('indian'):\n    raise OverflowError('value unrepresentable in Indian system words')\nconvert_number(n, 'indian')","handlingStrategy":"validation","validationCode":"from conversions.convert_number_to_words import NumberingSystem\nif abs(num) > NumberingSystem.max_value(system):\n    raise OverflowError(f'{num} exceeds {system} system range')","typeGuard":"def is_representable(num: int, system: str) -> bool:\n    from conversions.convert_number_to_words import NumberingSystem\n    return abs(num) <= NumberingSystem.max_value(system)","tryCatchPattern":"try:\n    convert_number(num, system)\nexcept ValueError as e:\n    if 'too large' in str(e):\n        raise OverflowError('number out of range for word conversion') from e\n    raise","preventionTips":["Bounds-check with max_value before converting","Avoid round power-of-ten literals in tests (exactly one past max)","Pick the numbering system consciously; caps differ per system"],"tags":["conversions","numbers-to-words","validation","overflow"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}